Submission #62150
ソースコード
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 | #include "bits/stdc++.h" #pragma GCC optimize("Ofast") // Begin Headelr {{{ using namespace std; #ifndef DEBUG #define dump(...) #endif #define all(x) x.begin(), x.end() #define rep(i, b, e) for (intmax_t i = (b), i##_limit = (e); i < i##_limit; ++i) #define reps(i, b, e) for (intmax_t i = (b), i##_limit = (e); i <= i##_limit; ++i) #define repr(i, b, e) for (intmax_t i = (b), i##_limit = (e); i >= i##_limit; --i) #define var(Type, ...) Type __VA_ARGS__; input(__VA_ARGS__) constexpr size_t operator "" _zu(unsigned long long value) { return value; }; constexpr intmax_t operator "" _jd(unsigned long long value) { return value; }; constexpr uintmax_t operator "" _ju(unsigned long long value) { return value; }; constexpr int INF = 0x3f3f3f3f; constexpr intmax_t LINF = 0x3f3f3f3f3f3f3f3f_jd; template < class T, class Compare = less<>> using MaxHeap = priority_queue<T, vector<T>, Compare>; template < class T, class Compare = greater<>> using MinHeap = priority_queue<T, vector<T>, Compare>; using imax = intmax_t; using usize = size_t ; inline void input() {} template < class Head, class ... Tail> inline void input(Head&& head, Tail&&... tail) { cin >> head; input(forward<Tail>(tail)...); } template < class T> inline istream& operator>>(istream &is, vector<T> &vec) { for (auto &e: vec) { is >> e; } return is; } inline void output() { cout << "\n" ; } template < class Head, class ... Tail> inline void output(Head&& head, Tail&&... tail) { cout << head; if ( sizeof ...(tail)) { cout << " " ; } output(forward<Tail>(tail)...); } template < class T> inline ostream& operator<<(ostream &os, const vector<T> &vec) { static constexpr const char *delim[] = { " " , "" }; for ( const auto &e: vec) { os << e << delim[&e == &vec.back()]; } return os; } template < class T> inline vector<T> makeVector( const T &initValue, size_t sz) { return vector<T>(sz, initValue); } template < class T, class ... Args> inline auto makeVector( const T &initValue, size_t sz, Args... args) { return vector<decltype(makeVector<T>(initValue, args...))>(sz, makeVector<T>(initValue, args...)); } template < class Func> class FixPoint : Func { public : explicit constexpr FixPoint(Func&& f) noexcept : Func(forward<Func>(f)) {} template < class ... Args> constexpr decltype(auto) operator()(Args&&... args) const { return Func::operator()(* this , std::forward<Args>(args)...); } }; template < class Func> static inline constexpr decltype(auto) makeFixPoint(Func&& f) noexcept { return FixPoint<Func>{forward<Func>(f)}; } template < class Container> struct reverse_t { Container &c; reverse_t(Container &c) : c(c) {} auto begin() { return c.rbegin(); } auto end() { return c.rend(); } }; template < class Container> auto reversed(Container &c) { return reverse_t<Container>(c); } template < class T> inline bool chmax(T &a, const T &b) noexcept { return b > a && (a = b, true ); } template < class T> inline bool chmin(T &a, const T &b) noexcept { return b < a && (a = b, true ); } template < class T> inline T diff( const T &a, const T &b) noexcept { return a < b ? b - a : a - b; } // }}} End Header constexpr int dy[] = {0, 1, 0, -1, -1, 1, 1, -1}; constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1}; const auto inside = []( int y, int x, int H, int W) -> bool { return (y >= 0 && x >= 0 && y < H && x < W); }; // SegmentTree {{{ template < class Monoid> struct SegmentTree { using Func = function<Monoid(Monoid, Monoid)>; const size_t sz; const Func fn; const Monoid unity; vector<Monoid> seg; SegmentTree( const size_t n, const Monoid &u, Func f) : sz(1 << (__lg(n + 5) + 1)), fn(f), unity(u), seg(sz * 2, unity) {} void set( size_t k, const Monoid &v) { seg[k + sz] = v; } Monoid& operator[]( size_t k) { return seg[k + sz]; } const Monoid& operator[]( size_t k) const { return seg[k + sz]; } void build() { for ( size_t k = sz - 1; k > 0; --k) { seg[k] = fn(seg[2 * k], seg[2 * k + 1]); } } void update( size_t k, const Monoid &x) { k += sz; seg[k] = x; while (k >>= 1) { seg[k] = fn(seg[2 * k], seg[2 * k + 1]); } } Monoid query( size_t a, size_t b) const { Monoid L = unity, R = unity; for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) { if (a & 1) L = fn(L, seg[a++]); if (b & 1) R = fn(seg[--b], R); } return fn(L, R); } }; // }}} // Geometry {{{ const long double EPS = 1e-10; const long double PI = acos (-1); static const int CCW_COUNTER_CLOCKWISE = 1; static const int CCW_CLOCKWISE = -1; static const int CCW_ONLINE_BACK = 2; static const int CCW_ONLINE_FRONT = -2; static const int CCW_ON_SEGMENT = 0; static const int ICC_SEPARATE = 4; static const int ICC_CIRCUMSCRIBE = 3; static const int ICC_INTERSECT = 2; static const int ICC_INSCRIBE = 1; static const int ICC_CONTAIN = 0; struct Real { long double x; Real( long double x = 0) : x(x) {} Real( const Real& rhs) { x = rhs.x; } Real operator+( const Real& rhs) const { return Real(x + rhs.x); } Real& operator+=( const Real& rhs) { return x += rhs.x, * this ; } Real operator-( const Real& rhs) const { return Real(x - rhs.x); } Real& operator-=( const Real& rhs) { return x -= rhs.x, * this ; } Real operator*( const Real& rhs) const { return Real(x * rhs.x); } Real& operator*=( const Real& rhs) { return x *= rhs.x, * this ; } Real operator/( const Real& rhs) const { return Real(x / rhs.x); } Real& operator/=( const Real& rhs) { return x /= rhs.x, * this ; } Real operator-() const { return Real(-x); } Real& operator++() { return ++x, * this ; } Real& operator--() { return --x, * this ; } Real operator++( int ) { Real tmp(x); return ++x, tmp; } Real operator--( int ) { Real tmp(x); return --x, tmp; } bool operator==( const Real& rhs) const { return fabs (x - rhs.x) < EPS; } bool operator!=( const Real& rhs) const { return !(* this == rhs); } bool operator<( const Real& rhs) const { return (* this == rhs) ? false : x < rhs.x; } bool operator>( const Real& rhs) const { return (* this == rhs) ? false : x > rhs.x; } bool operator<=( const Real& rhs) const { return (* this == rhs) ? true : x < rhs.x; } bool operator>=( const Real& rhs) const { return (* this == rhs) ? true : x > rhs.x; } template < class T> explicit operator T() const { return static_cast <T>(x); } friend istream& operator>>(istream& is, Real& rhs) { is >> rhs.x; return is; } friend ostream& operator<<(ostream& os, const Real& rhs) { os << rhs.x; return os; } friend Real pow ( const Real& n, const Real& p) { return pow (n.x, p.x); } friend Real pow (Real n, intmax_t p) { Real ret = 1; for (; p > 0; p >>= 1) { if (p & 1) ret *= n; n *= n; } return ret; } friend Real abs ( const Real& rhs) { return abs (rhs.x); } friend Real sin ( const Real& rhs) { return sin (rhs.x); } friend Real cos ( const Real& rhs) { return cos (rhs.x); } friend Real tan ( const Real& rhs) { return tan (rhs.x); } friend Real asin ( const Real& rhs) { return asin (rhs.x); } friend Real acos ( const Real& rhs) { return acos (rhs.x); } friend Real atan ( const Real& rhs) { return atan (rhs.x); } friend Real atan2 ( const Real& lhs, const Real& rhs) { return atan2 (lhs.x, rhs.x); } friend Real sqrt ( const Real& rhs) { return sqrt (rhs.x); } friend Real ceil ( const Real& rhs) { return ceil (rhs.x); } friend Real floor ( const Real& rhs) { return floor (rhs.x); } friend Real round( const Real& rhs) { return round(rhs.x); } }; using real_t = Real; real_t operator "" _r( long double value) { return value; }; struct Point { real_t x, y; Point(real_t x = 0, real_t y = 0) : x(x), y(y) {} Point operator+( const Point& rhs) const { return Point(x + rhs.x, y + rhs.y); } Point operator-( const Point& rhs) const { return Point(x - rhs.x, y - rhs.y); } Point operator*( const real_t& rhs) const { return Point(x * rhs, y * rhs); } Point operator/( const real_t& rhs) const { return Point(x / rhs, y / rhs); } Point operator-() const { return Point(-x, -y); } bool operator==( const Point& rhs) const { return x == rhs.x && y == rhs.y; } bool operator!=( const Point& rhs) const { return !(* this == rhs); } bool operator<( const Point& rhs) const { return (x == rhs.x) ? y < rhs.y : x < rhs.x; } bool operator>( const Point& rhs) const { return (x == rhs.x) ? y > rhs.y : x > rhs.x; } bool operator<=( const Point& rhs) const { return (* this == rhs) ? true : * this < rhs; } bool operator>=( const Point& rhs) const { return (* this == rhs) ? true : * this > rhs; } friend istream& operator>>(istream& is, Point& rhs) { is >> rhs.x >> rhs.y; return is; } friend ostream& operator<<(ostream& os, const Point& rhs) { os << rhs.x << ' ' << rhs.y; return os; } }; using Vector = Point; using Polygon = vector<Point>; real_t norm( const Vector& a) { return a.x * a.x + a.y * a.y; } real_t len( const Vector& a) { return sqrt (norm(a)); } real_t dot( const Vector& a, const Vector& b) { return a.x * b.x + a.y * b.y; } real_t cross( const Vector& a, const Vector& b) { return a.x * b.y - a.y * b.x; } struct Segment { Point p1, p2; Segment(Point p1 = Point(), Point p2 = Point()) : p1(p1), p2(p2) {} bool operator==( const Segment& rhs) const { return p1 == rhs.p1 && p2 == rhs.p2; } bool operator!=( const Segment& rhs) const { return !(* this == rhs); } friend istream& operator>>(istream& is, Segment& rhs) { is >> rhs.p1 >> rhs.p2; return is; } friend ostream& operator<<(ostream& os, const Segment& rhs) { os << rhs.p1 << ' ' << rhs.p2; return os; } }; using Line = Segment; struct Circle { Point c; real_t r; Circle(Point c = Point(), real_t r = 0) : c(c), r(r) {} bool operator==( const Circle& rhs) const { return c == rhs.c && r == rhs.r; } bool operator!=( const Circle& rhs) const { return !(* this == rhs); } friend istream& operator>>(istream& is, Circle& rhs) { is >> rhs.c >> rhs.r; return is; } friend ostream& operator<<(ostream& os, const Circle& rhs) { os << rhs.c << rhs.r; return os; } }; real_t len( const Segment& s) { return len(s.p1 - s.p2); } bool isParallel( const Vector& a, const Vector& b) { return cross(a, b) == 0.0_r; } bool isParallel( const Point& a1, const Point& a2, const Point& b1, const Point& b2) { return isParallel(a1 - a2, b1 - b2); } bool isParallel( const Segment& s1, const Segment& s2) { return isParallel(s1.p1, s1.p2, s2.p1, s2.p2); } bool isOrthogonal( const Vector& a, const Vector& b) { return dot(a, b) == 0.0_r; } bool isOrthogonal( const Point& a1, const Point& a2, const Point& b1, const Point& b2) { return isOrthogonal(a1 - a2, b1 - b2); } bool isOrthogonal( const Segment& s1, const Segment& s2) { return isOrthogonal(s1.p1, s1.p2, s2.p1, s2.p2); } Point project( const Segment& s, const Point& p) { const Vector base = s.p2 - s.p1; const Vector hypo = p - s.p1; const real_t r = dot(hypo, base) / norm(base); return s.p1 + base * r; } Point reflect( const Segment& s, const Point& p) { return p + (project(s, p) - p) * 2.0; } real_t arg( const Vector& p) { return atan2 (p.y, p.x); } Vector polar(real_t r, real_t ang) { return Point(r * cos (ang), r * sin (ang)); } int ccw( const Point& p0, const Point& p1, const Point& p2); bool intersectSS( const Point& p1, const Point& p2, const Point& p3, const Point& p4); bool intersectSS( const Segment& s1, const Segment& s2); bool intersectSG( const Segment& s, const Polygon& g); int intersectCC(Circle c1, Circle c2); bool intersectLC( const Line& l, const Circle& c); int intersectSC( const Segment& s, const Circle& c); real_t getDistancePP( const Point& p1, const Point& p2); real_t getDistanceLP( const Line& l, const Point& p); real_t getDistanceSP( const Segment& s, const Point& p); real_t getDistanceSS( const Segment& s1, const Segment& s2); Point getcrossPointSS( const Segment& s1, const Segment& s2); Point getcrossPointLL( const Line& l1, const Line& l2); Polygon getcrossPointLC( const Line& l, const Circle& c); Polygon getcrossPointSC( const Segment& s, const Circle& c); Polygon getcrossPointCC( const Circle &c1, const Circle &c2); bool isConvex( const Polygon& g); int contains( const Polygon& g, const Point& p); Polygon convexFull(Polygon g, bool ONSEG); real_t area( const Polygon& g); int ccw( const Point& p0, const Point& p1, const Point& p2) { Vector a = p1 - p0; Vector b = p2 - p0; if (cross(a, b) > 0.0_r) return CCW_COUNTER_CLOCKWISE; if (cross(a, b) < 0.0_r) return CCW_CLOCKWISE; if (dot(a, b) < 0.0_r) return CCW_ONLINE_BACK; if (norm(a) < norm(b)) return CCW_ONLINE_FRONT; return CCW_ON_SEGMENT; } bool intersectSS( const Point& p1, const Point& p2, const Point& p3, const Point& p4) { return ccw(p1, p2, p3) * ccw(p1, p2, p4) < 0 && ccw(p3, p4, p1) * ccw(p3, p4, p2) < 0; } bool intersectSS( const Segment& s1, const Segment& s2) { return intersectSS(s1.p1, s1.p2, s2.p1, s2.p2); } bool intersectSG( const Segment& s, const Polygon& g) { const size_t N = g.size(); for ( size_t i = 0; i < N; ++i) { if (intersectSS(Segment(g[i], g[(i + 1) % N]), s)) return true ; } return false ; } int intersectCC(Circle c1, Circle c2) { if (c1.r < c2.r) swap(c1, c2); const real_t d = len(c1.c - c2.c); const real_t r = c1.r + c2.r; if (d == r) return ICC_CIRCUMSCRIBE; if (d > r) return ICC_SEPARATE; if (d + c2.r == c1.r) return ICC_INSCRIBE; if (d + c2.r < c1.r) return ICC_CONTAIN; return ICC_INTERSECT; } bool intersectLC( const Line& l, const Circle& c) { return getDistanceSP(l, c.c) <= c.r; } int intersectSC( const Segment& s, const Circle& c) { const Point h = project(s, c.c); if (norm(h - c.c) - c.r * c.r > 0.0_r) return 0; const real_t d1 = getDistancePP(c.c, s.p1); const real_t d2 = getDistancePP(c.c, s.p2); if (d1 < c.r && d2 < c.r) return 0; if ((d1 < c.r && d2 > c.r) || (d1 > c.r && d2 < c.r)) return 1; if (dot(s.p1 - h, s.p2 - h) < 0.0_r) return 2; return 0; } real_t getDistancePP( const Point& p1, const Point& p2) { return len(p2 - p1); } real_t getDistanceLP( const Line& l, const Point& p) { return abs (cross(l.p2 - l.p1, p - l.p1) / len(l.p2 - l.p1)); } real_t getDistanceSP( const Segment& s, const Point& p) { if (dot(s.p2 - s.p1, p - s.p1) < 0.0_r) return getDistancePP(p, s.p1); if (dot(s.p1 - s.p2, p - s.p2) < 0.0_r) return getDistancePP(p, s.p2); return getDistanceLP(s, p); } real_t getDistanceSS( const Segment& s1, const Segment& s2) { if (intersectSS(s1, s2)) return 0.0; const real_t opt1 = getDistanceSP(s1, s2.p1); const real_t opt2 = getDistanceSP(s1, s2.p2); const real_t opt3 = getDistanceSP(s2, s1.p1); const real_t opt4 = getDistanceSP(s2, s1.p2); return min({opt1, opt2, opt3, opt4}); } Point getcrossPointSS( const Segment& s1, const Segment& s2) { Vector base = s2.p2 - s2.p1; const real_t d1 = abs (cross(base, s1.p1 - s2.p1)); const real_t d2 = abs (cross(base, s1.p2 - s2.p1)); const real_t t = d1 / (d1 + d2); return s1.p1 + (s1.p2 - s1.p1) * t; } Polygon getcrossPointLC( const Line& l, const Circle& c) { Polygon ps; const Point pr = project(l, c.c); const Vector e = (l.p2 - l.p1) / len(l.p2 - l.p1); if (getDistanceLP(l, c.c) == c.r) { ps.emplace_back(pr); return ps; } const real_t base = sqrt (c.r * c.r - norm(pr - c.c)); ps.emplace_back(pr + e * base); ps.emplace_back(pr - e * base); return ps; } Polygon getcrossPointSC( const Segment& s, const Circle& c) { const Line l(s); Polygon ret = getcrossPointLC(l, c); if (intersectSC(s, c) == 2) return ret; if (ret.size() > 1) { if (dot(l.p1 - ret[0], l.p2 - ret[0]) > 0.0) swap(ret[0], ret[1]); ret.pop_back(); } return ret; } Polygon getcrossPointCC( const Circle& c1, const Circle& c2) { Polygon p(2); const real_t d = getDistancePP(c1.c, c2.c); const real_t a = acos ((c1.r * c1.r + d * d - c2.r * c2.r) / (2.0_r * c1.r * d)); const real_t t = arg(c2.c - c1.c); p[0] = c1.c + polar(c1.r, t + a); p[1] = c1.c + polar(c1.r, t - a); return p; } bool isConvex( const Polygon& g) { const size_t N = g.size(); for ( size_t i = 0; i < N; ++i) { const int state = ccw(g[i], g[(i + 1) % N], g[(i + 2) % N]); if (state == CCW_CLOCKWISE) return false ; } return true ; } // IN:2 ON:1 OUT:0 int contains( const Polygon& g, const Point& p) { const size_t N = g.size(); bool valid = false ; for ( size_t i = 0; i < N; ++i) { Point a = g[i] - p, b = g[(i + 1) % N] - p; if ( abs (cross(a, b)) == 0.0_r && dot(a, b) <= 0.0_r) return 1; if (a.y > b.y) swap(a, b); if (a.y <= 0.0_r && 0.0_r < b.y && cross(a, b) > 0.0_r) valid ^= 1; } return (valid ? 2 : 0); } // Counter Clockwise Polygon convexFull(Polygon g, bool ONSEG) { Polygon u, l; if (g.size() < 3) return g; sort(g.begin(), g.end()); u.emplace_back(g[0]); u.emplace_back(g[1]); l.emplace_back(g[g.size() - 1]); l.emplace_back(g[g.size() - 2]); if (ONSEG) { for ( int i = 2; i < g.size(); ++i) { for ( int n = u.size(); n >= 2 && ccw(u[n - 2], u[n - 1], g[i]) == CCW_COUNTER_CLOCKWISE; --n) { u.pop_back(); } u.emplace_back(g[i]); } for ( int i = g.size() - 3; i >= 0; --i) { for ( int n = l.size(); n >= 2 && ccw(l[n - 2], l[n - 1], g[i]) == CCW_COUNTER_CLOCKWISE; --n) { l.pop_back(); } l.emplace_back(g[i]); } } else { for ( int i = 2; i < g.size(); ++i) { for ( int n = u.size(); n >= 2 && ccw(u[n - 2], u[n - 1], g[i]) != CCW_CLOCKWISE; --n) { u.pop_back(); } u.emplace_back(g[i]); } for ( int i = g.size() - 3; i >= 0; --i) { for ( int n = l.size(); n >= 2 && ccw(l[n - 2], l[n - 1], g[i]) != CCW_CLOCKWISE; --n) { l.pop_back(); } l.emplace_back(g[i]); } } reverse(l.begin(), l.end()); for ( int i = u.size() - 2; i >= 1; --i) l.emplace_back(u[i]); return l; } real_t area( const Polygon& g) { const size_t N = g.size(); real_t res = 0; for ( size_t i = 0; i < g.size(); ++i) { res += cross(g[i], g[(i + 1) % N]) / 2.0; } return res; } // }}} imax power(imax x, imax p) { imax res = 1; while (p > 0) { if (p & 1) { res *= x; } x *= x; p >>= 1; } return res; } imax digitSum(imax y) { imax res = 0; while (y > 0) { res += y % 10; y /= 10; } return res; } const imax MOD = imax(1e9) + 7; // ModInt {{{ template <intmax_t MOD> class ModInt { intmax_t value; public : inline ModInt( const ModInt& other) : value(other.value) {} inline ModInt( const intmax_t& value = 0) { if (value >= MOD) { this ->value = value % MOD; } else if (value < 0) { this ->value = (value % MOD + MOD) % MOD; } else { this ->value = value; } } template < class T> explicit inline operator T() const { return static_cast <T>(value); } inline ModInt inverse() const { return ModInt:: pow (value, MOD - 2); } inline ModInt& operator+=( const ModInt& other) { if ((value += other.value) >= MOD) value -= MOD; return * this ; } inline ModInt& operator-=( const ModInt& other) { if ((value -= other.value) < 0) value += MOD; return * this ; } inline ModInt& operator*=( const ModInt& other) { value = (value * other.value) % MOD; return * this ; } inline ModInt& operator/=( const ModInt& other) { value = (value * other.inverse().value) % MOD; return * this ; } inline ModInt operator+( const ModInt& other) { return ModInt(* this ) += other; } inline ModInt operator-( const ModInt& other) { return ModInt(* this ) -= other; } inline ModInt operator*( const ModInt& other) { return ModInt(* this ) *= other; } inline ModInt operator/( const ModInt& other) { return ModInt(* this ) /= other; } inline ModInt& operator++() { value = (value + 1) % MOD; return * this ; } inline ModInt& operator--() { value = (value - 1 + MOD) % MOD; return * this ; } inline ModInt operator++( int ) { ModInt tmp(* this ); ++* this ; return tmp; } inline ModInt operator--( int ) { ModInt tmp(* this ); --* this ; return tmp; } inline bool operator==( const ModInt& other) { return value == other.value; } inline bool operator!=( const ModInt& other) { return value != other.value; } friend ostream& operator<<(ostream &os, const ModInt& other) { os << other.value; return os; } friend istream& operator>>(istream &is, ModInt& other) { is >> other.value; other.value = (other.value % MOD + MOD) % MOD; return is; } static constexpr inline ModInt pow (intmax_t n, intmax_t p) { intmax_t ret = 1; for (; p > 0; p >>= 1) { if (p & 1) ret = (ret * n) % MOD; n = (n * n) % MOD; } return ret; } }; using Mint = ModInt<MOD>; // }}} // Edge {{{ template < class Weight> struct Edge { size_t from, to; Weight weight; Edge() {} Edge( size_t from, size_t to, Weight weight = 1) : from(from), to(to), weight(weight) {} bool operator<( const Edge &rhs) const { return weight < rhs.weight; } bool operator>( const Edge &rhs) const { return weight > rhs.weight; } operator size_t () const { return to; } }; // }}} // Graph {{{ template < class Weight> class Graph : public vector<vector<Edge<Weight>>> { using graph = vector<vector<Edge<Weight>>>; public : Graph() {} Graph( const size_t V) : graph(V) {} void connect( size_t from, size_t to, Weight weight = 1) { (* this )[from].emplace_back(from, to, weight); } friend ostream& operator<<(ostream &strm, const Graph &G) { for ( size_t v = 0; v < G.size(); ++v) { strm << '[' << setw(2) << v << ']' ; for ( const auto &e: G[v]) { strm << ' ' << setw(2) << e.to; } strm << '\n' ; } return strm; } }; // }}} signed main() { ios_base::sync_with_stdio( false ); cin.tie(nullptr); cout.setf(ios_base::fixed); cout.precision(10); var( int , a, b, c); assert (-100 <= a && a <= 100); assert (-100 <= b && b <= 100); assert (-100 <= c && c <= 100); assert (a != b && b != c && c != a); output(max({diff(a, b), diff(b, c), diff(c, a)})); return 0; } |
ステータス
項目 | データ |
---|---|
問題 | 1341 - Maximum Distance |
ユーザー名 | syoribu |
投稿日時 | 2020-08-14 09:37:12 |
言語 | C++17 |
状態 | Accepted |
得点 | 100 |
ソースコード長 | 24204 Byte |
最大実行時間 | 25 ms |
最大メモリ使用量 | 700 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 100 / 100 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
in01.txt | AC | 19 ms | 600 KB |
1
|
in02.txt | AC | 20 ms | 424 KB |
1
|
in03.txt | AC | 21 ms | 512 KB |
1
|
in04.txt | AC | 21 ms | 468 KB |
1
|
in05.txt | AC | 23 ms | 552 KB |
1
|
in06.txt | AC | 17 ms | 504 KB |
1
|
in07.txt | AC | 21 ms | 460 KB |
1
|
in08.txt | AC | 18 ms | 548 KB |
1
|
in09.txt | AC | 21 ms | 500 KB |
1
|
in10.txt | AC | 20 ms | 460 KB |
1
|
in11.txt | AC | 23 ms | 540 KB |
1
|
in12.txt | AC | 17 ms | 628 KB |
1
|
in13.txt | AC | 20 ms | 580 KB |
1
|
in14.txt | AC | 16 ms | 660 KB |
1
|
in15.txt | AC | 18 ms | 620 KB |
1
|
sample01.txt | AC | 18 ms | 700 KB |
1
|
sample02.txt | AC | 25 ms | 660 KB |
1
|