QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#267708 | #7680. Subway | Hongzy | AC ✓ | 1ms | 3600kb | C++17 | 2.7kb | 2023-11-27 16:42:31 | 2023-11-27 16:42:31 |
Judging History
answer
//Test
//source code by ckiseki, https://qoj.ac/submission/245019
#include <bits/stdc++.h>
using namespace std;
constexpr int R = 1'000'000'000;
using ll = int64_t;
void exgcd(ll x, ll y, ll &a, ll &b) {
if (y == 0) a = 1, b = 0;
else exgcd(y, x % y, b, a), b -= (x / y) * a;
}
pair<ll, ll> MakeMid(ll a, ll b, ll v) { //ax + by = v
ll x, y;
exgcd(a, b, x, y);
// ll vv = v % abs(a);
x *= v, y *= v;
return {x, y};
// return {x + v / abs(a), y};
}
int main() {
mt19937 rnd(7122);
uniform_int_distribution<ll> C(-10'000, 10'000);
int n;
cin >> n;
if (n == 1) {
int x, y, c;
cin >> x >> y >> c;
cout << c << '\n';
for (int i = 0; i < c; ++i) {
cout << 2 << ' ' << x << ' ' << y;
cout << ' ' << x + i << ' ' << y + i + 1 << '\n';
}
return 0;
}
vector<tuple<ll, ll, int>> v_(n);
for (auto &[x, y, c] : v_)
cin >> x >> y >> c;
while (true) {
ll a = C(rnd), b = C(rnd);
if (a == 0 and b == 0)
continue;
ll g = gcd(abs(a), abs(b));
a /= g, b /= g;
auto v = v_;
auto f = [&](ll x, ll y) {
return a * x + b * y;
};
sort(v.begin(), v.end(), [&](const auto &lhs, const auto &rhs) {
return f(get<0>(lhs), get<1>(lhs)) < f(get<0>(rhs), get<1>(rhs));
});
bool valid = true;
for (int i = 1; i < n; ++i) {
valid &= f(get<0>(v[i]), get<1>(v[i])) - f(get<0>(v[i - 1]), get<1>(v[i - 1])) > 1;
}
if (not valid)
continue;
vector<pair<ll, ll>> mid;
for (int i = 0; i + 1 < n; ++i) {
const auto [x1, y1, _] = v[i];
ll fv = f(x1, y1) + 1;
auto [x2, y2] = MakeMid(a, b, fv);
mid.emplace_back(x2, y2);
}
vector<vector<pair<ll, ll>>> ans;
while (true) {
bool all0 = true;
for (auto [_, __, c] : v)
all0 &= c == 0;
if (all0)
break;
ans.push_back({});
for (int i = 0; i < n; ++i) {
auto &[x, y, c] = v[i];
if (c == 0) {
x -= b, y += a;
} else {
c -= 1;
}
ans.back().emplace_back(x, y);
if (i + 1 < n) {
ans.back().push_back(mid[i]);
mid[i].first -= b;
mid[i].second += a;
}
}
}
for (const auto &ansi : ans) {
for (auto [x, y] : ansi) {
valid &= -R <= x and x <= R;
valid &= -R <= y and y <= R;
}
}
// if (not valid)
// continue;
cout << ans.size() << '\n';
for (const auto &ansi : ans) {
cout << ansi.size();
for (auto [x, y] : ansi) {
cout << ' ' << x << ' ' << y;
}
cout << '\n';
}
break;
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3456kb
input:
3 1 2 1 2 1 2 3 3 2
output:
2 5 1 2 -21420 -32040 3 3 63665 95230 2 1 5 360 539 -21061 -31503 3 3 64024 95767 2 1
result:
ok ok Sum L = 10
Test #2:
score: 0
Accepted
time: 0ms
memory: 3416kb
input:
1 1 1 1
output:
1 2 1 1 1 2
result:
ok ok Sum L = 2
Test #3:
score: 0
Accepted
time: 0ms
memory: 3420kb
input:
1 1 1 50
output:
50 2 1 1 1 2 2 1 1 2 3 2 1 1 3 4 2 1 1 4 5 2 1 1 5 6 2 1 1 6 7 2 1 1 7 8 2 1 1 8 9 2 1 1 9 10 2 1 1 10 11 2 1 1 11 12 2 1 1 12 13 2 1 1 13 14 2 1 1 14 15 2 1 1 15 16 2 1 1 16 17 2 1 1 17 18 2 1 1 18 19 2 1 1 19 20 2 1 1 20 21 2 1 1 21 22 2 1 1 22 23 2 1 1 23 24 2 1 1 24 25 2 1 1 25 26 2 1 1 26 27 2 ...
result:
ok ok Sum L = 100
Test #4:
score: 0
Accepted
time: 1ms
memory: 3476kb
input:
50 662 -567 48 728 -120 7 307 669 27 -885 -775 21 100 242 9 -784 -537 41 940 198 46 736 -551 30 -449 456 16 -945 382 18 -182 810 49 213 187 44 853 245 48 617 -305 19 -81 261 3 617 208 8 -548 -652 6 -888 -667 14 -371 -812 43 202 -702 10 -668 -725 5 961 -919 33 -870 -697 50 428 810 29 560 405 7 348 -3...
output:
50 99 -926 671 -87839850 -131390700 -945 382 -76707638 -114739156 -683 731 -74874681 -111997422 -558 825 -70902580 -106055960 -825 381 -68996557 -103204934 -981 -193 -54443571 -81436602 -449 456 -48173104 -72057248 -182 810 -46234237 -69157094 -331 176 -28670670 -42885540 -888 -667 -28250838 -422575...
result:
ok ok Sum L = 4950
Test #5:
score: 0
Accepted
time: 1ms
memory: 3372kb
input:
50 -772 697 1 -756 -909 1 659 923 1 850 471 1 260 -24 1 473 -639 1 -575 393 1 -466 197 1 333 -637 1 -192 -890 1 103 546 1 749 -723 1 -573 613 1 214 -138 1 277 928 1 266 291 1 911 275 1 -680 -67 1 69 190 1 -197 -795 1 684 618 1 729 -115 1 -658 -229 1 -595 -470 1 898 -172 1 401 81 1 133 685 1 223 400 ...
output:
1 99 -772 697 -79109534 -118331908 -530 890 -71890161 -107533182 -532 838 -69796475 -104401450 -573 613 -62804273 -93942526 -304 897 -57747130 -86378060 -389 708 -55104616 -82425392 -575 393 -53533459 -80075258 -254 815 -51048858 -76358796 -187 841 -47878103 -71615986 -346 458 -41676537 -62339694 -6...
result:
ok ok Sum L = 99
Test #6:
score: 0
Accepted
time: 1ms
memory: 3416kb
input:
50 -56 747 3 993 -490 4 930 -139 1 -298 -330 1 938 -351 5 -973 100 5 -472 44 4 345 628 5 481 -91 4 789 581 5 457 -29 4 871 -799 1 692 994 4 699 854 2 893 -33 1 -483 256 3 -962 -540 2 846 -893 1 830 609 5 845 -383 2 -552 -966 1 -544 -51 1 564 186 4 -615 -675 1 618 -911 3 -561 -302 4 -293 667 3 -334 -...
output:
5 99 -999 330 -77936908 -116577896 -842 381 -70082908 -104829896 -973 100 -66449600 -99395200 -104 972 -48170605 -72053510 -293 667 -47218367 -70629154 -483 256 -41801606 -62526772 -962 -540 -38405227 -57446474 -159 609 -36177547 -54114314 -56 747 -35491036 -53087432 -544 -51 -32584342 -48739604 -47...
result:
ok ok Sum L = 495
Test #7:
score: 0
Accepted
time: 1ms
memory: 3440kb
input:
50 600 997 5 -893 -204 3 408 443 1 -560 -748 7 -647 161 6 -285 -980 1 87 -582 7 -48 -721 7 997 285 2 -189 -728 8 525 222 4 -324 816 9 760 317 3 753 -480 10 -813 -921 3 -325 -875 8 -747 816 10 -627 605 7 775 786 6 136 -54 2 274 948 10 216 -113 7 924 68 3 101 576 8 60 -501 2 898 801 8 -767 -974 10 -99...
output:
10 99 -980 753 -94793734 -141792308 -747 816 -82595758 -123546596 -627 605 -65913267 -98592954 -324 816 -55564789 -83113718 -982 -212 -53695775 -80318050 -419 564 -50869882 -76091084 -972 -312 -48784645 -72971990 -893 -204 -48350176 -72322112 -647 161 -48223203 -72132186 -99 819 -41314777 -61798574 ...
result:
ok ok Sum L = 990
Test #8:
score: 0
Accepted
time: 1ms
memory: 3600kb
input:
50 24 -889 49 117 418 49 25 524 44 980 -416 43 -494 357 41 -287 -285 46 151 574 41 -289 68 49 -515 -540 41 -367 -178 47 -887 151 45 197 -272 47 714 724 45 -737 94 49 810 830 47 808 -695 41 537 -637 49 -142 -167 44 -749 -631 47 445 -444 42 801 910 43 59 363 42 -912 466 50 -649 -479 48 -958 -511 49 88...
output:
50 99 -998 343 -78428378 -117313036 -912 466 -78187403 -116952586 -615 809 -73861515 -110481930 -486 866 -68053125 -101793750 -887 151 -63132713 -94433806 -737 94 -51112166 -76453492 -868 -114 -50597491 -75683642 -195 889 -50439935 -75447970 -308 652 -47536097 -71104414 -494 357 -46819360 -70032320 ...
result:
ok ok Sum L = 4950
Test #9:
score: 0
Accepted
time: 0ms
memory: 3500kb
input:
50 151 -171 50 -367 -951 50 808 569 50 150 -618 50 27 -476 50 -846 729 50 549 -456 50 50 646 50 294 -70 50 -571 104 50 128 -265 50 913 -700 50 267 -965 50 896 846 50 -2 713 50 21 679 50 -515 975 50 168 180 50 -369 -98 50 676 115 50 643 -779 50 920 -237 50 -324 450 50 149 -378 50 -882 -602 50 -126 -7...
output:
50 99 -846 729 -85205428 -127450136 -841 601 -79417625 -118792750 -515 975 -74562901 -111531062 -501 927 -71617651 -107125562 -851 279 -66300493 -99172166 -474 780 -63612283 -95151146 -544 307 -47878460 -71616520 -571 104 -40931478 -61225236 -324 450 -39928903 -59725586 -604 -168 -31420165 -46998230...
result:
ok ok Sum L = 4950
Test #10:
score: 0
Accepted
time: 1ms
memory: 3452kb
input:
50 4 5 34 1 -5 24 -4 -4 32 -3 3 28 0 -1 21 1 -4 25 0 0 30 0 -4 42 -3 -2 44 -5 -3 37 4 -1 46 5 2 20 2 2 37 -2 5 35 -2 -1 39 2 4 32 -4 -3 42 0 3 32 3 5 47 -4 1 2 5 -1 17 -5 -4 5 -2 2 29 -5 1 11 2 -5 43 4 4 14 -5 0 9 0 -5 17 5 1 27 -3 0 24 -1 4 16 5 0 50 3 -2 18 1 -2 6 2 -1 29 -1 3 38 1 5 36 -3 1 28 -3...
output:
50 99 -3 5 -405195 -606090 -5 1 -362117 -541654 -2 5 -341292 -510504 -3 3 -319753 -478286 -5 0 -319396 -477752 -4 1 -298214 -446068 -1 5 -277389 -414918 -1 4 -234668 -351016 -3 1 -234311 -350482 0 5 -213486 -319332 -2 2 -213129 -318798 -1 3 -191947 -287114 -3 0 -191590 -286580 -5 -3 -191233 -286046 ...
result:
ok ok Sum L = 4950
Test #11:
score: 0
Accepted
time: 0ms
memory: 3380kb
input:
50 2 0 2 2 -3 2 4 1 2 -3 -3 2 -5 1 2 5 3 2 -5 -3 2 -3 -2 2 2 -1 2 2 3 2 4 4 1 1 -4 1 5 -1 2 -4 1 2 3 -2 1 -1 2 2 5 -5 2 -2 1 2 -5 -1 2 -2 -1 2 -1 -2 2 5 5 1 0 -2 2 1 1 1 2 2 2 3 5 2 -2 -4 1 -3 5 1 4 2 2 -4 -4 2 -3 2 1 5 0 2 -2 -2 2 -4 4 1 -2 5 2 2 5 1 3 -5 2 -4 5 2 -5 5 2 -2 4 2 -5 -5 2 -2 2 2 -3 -4...
output:
2 99 -5 5 -533001 -797262 -4 5 -469098 -701676 -4 4 -426377 -637774 -3 5 -405195 -606090 -5 1 -362117 -541654 -2 5 -341292 -510504 -2 4 -298571 -446602 -4 1 -298214 -446068 -3 2 -277032 -414384 -5 -1 -276675 -413850 -2 2 -213129 -318798 -3 0 -191590 -286580 -5 -3 -191233 -286046 -2 1 -170408 -254896...
result:
ok ok Sum L = 198
Test #12:
score: 0
Accepted
time: 1ms
memory: 3532kb
input:
50 4 3 49 -5 -3 49 0 -3 50 -2 -4 49 -5 -5 50 4 0 49 -1 -2 49 -2 0 49 1 2 50 -1 -5 50 -5 -1 50 -5 5 49 2 0 50 -2 -3 50 -4 -5 50 0 -2 50 -5 4 50 -1 1 49 -1 -4 49 -3 -1 49 1 -3 50 -4 1 50 0 5 50 1 -2 50 -1 5 50 4 2 50 4 -3 49 1 -4 49 -1 -1 49 -3 -5 50 4 -4 50 3 2 49 3 -3 49 0 2 50 -3 -4 49 5 -1 49 -3 5...
output:
50 99 -5 5 -533001 -797262 -5 4 -490280 -733360 -4 4 -426377 -637774 -3 5 -405195 -606090 -4 1 -298214 -446068 -1 5 -277389 -414918 -5 -1 -276675 -413850 -2 3 -255850 -382700 0 5 -213486 -319332 -5 -3 -191233 -286046 0 4 -170765 -255430 -3 -1 -148869 -222678 -2 0 -127687 -190994 1 4 -106862 -159844 ...
result:
ok ok Sum L = 4950
Test #13:
score: 0
Accepted
time: 1ms
memory: 3496kb
input:
50 114 514 30 115 514 41 116 514 6 117 514 49 118 514 10 119 514 49 120 514 1 121 514 7 122 514 3 123 514 4 124 514 1 125 514 12 126 514 15 127 514 16 128 514 34 129 514 24 130 514 49 131 514 43 132 514 25 133 514 12 134 514 26 135 514 13 136 514 12 137 514 15 138 514 7 139 514 25 140 514 5 141 514 ...
output:
49 99 114 514 -14673533 -21948646 115 514 -14609630 -21853060 116 514 -14545727 -21757474 117 514 -14481824 -21661888 118 514 -14417921 -21566302 119 514 -14354018 -21470716 120 514 -14290115 -21375130 121 514 -14226212 -21279544 122 514 -14162309 -21183958 123 514 -14098406 -21088372 124 514 -14034...
result:
ok ok Sum L = 4851
Test #14:
score: 0
Accepted
time: 1ms
memory: 3564kb
input:
50 191 981 19 191 980 41 191 979 20 191 978 14 191 977 2 191 976 49 191 975 40 191 974 3 191 973 20 191 972 6 191 971 13 191 970 4 191 969 4 191 968 47 191 967 32 191 966 11 191 965 34 191 964 30 191 963 3 191 962 16 191 961 24 191 960 30 191 959 34 191 958 31 191 957 24 191 956 29 191 955 42 191 95...
output:
49 99 191 981 -29703709 -44430758 191 980 -29660988 -44366856 191 979 -29618267 -44302954 191 978 -29575546 -44239052 191 977 -29532825 -44175150 191 976 -29490104 -44111248 191 975 -29447383 -44047346 191 974 -29404662 -43983444 191 973 -29361941 -43919542 191 972 -29319220 -43855640 191 971 -29276...
result:
ok ok Sum L = 4851
Test #15:
score: 0
Accepted
time: 1ms
memory: 3496kb
input:
50 -123 456 47 -122 457 35 -121 458 25 -120 459 35 -119 460 30 -118 461 33 -117 462 21 -116 463 31 -115 464 21 -114 465 35 -113 466 20 -112 467 17 -111 468 25 -110 469 3 -109 470 29 -108 471 35 -107 472 4 -106 473 44 -105 474 4 -104 475 28 -103 476 49 -102 477 9 -101 478 39 -100 479 9 -99 480 21 -98...
output:
50 99 -123 456 -27340726 -40896212 -122 457 -27319544 -40864528 -121 458 -27298362 -40832844 -120 459 -27277180 -40801160 -119 460 -27255998 -40769476 -118 461 -27234816 -40737792 -117 462 -27213634 -40706108 -116 463 -27192452 -40674424 -115 464 -27171270 -40642740 -114 465 -27150088 -40611056 -113...
result:
ok ok Sum L = 4950
Test #16:
score: 0
Accepted
time: 1ms
memory: 3476kb
input:
50 321 -525 46 322 -526 14 323 -527 16 324 -528 38 325 -529 22 326 -530 24 327 -531 48 328 -532 5 329 -533 7 330 -534 30 331 -535 25 332 -536 2 333 -537 13 334 -538 1 335 -539 33 336 -540 8 337 -541 9 338 -542 2 339 -543 29 340 -544 17 341 -545 41 342 -546 39 343 -547 9 344 -548 47 345 -549 47 346 -...
output:
50 99 321 -525 42941507 64231834 322 -526 43048131 64391322 323 -527 43154755 64550810 324 -528 43261379 64710298 325 -529 43368003 64869786 326 -530 43474627 65029274 327 -531 43581251 65188762 328 -532 43687875 65348250 329 -533 43794499 65507738 330 -534 43901123 65667226 331 -535 44007747 658267...
result:
ok ok Sum L = 4950
Test #17:
score: 0
Accepted
time: 1ms
memory: 3588kb
input:
50 -444 -555 23 -445 -556 32 -446 -557 36 -447 -558 29 -448 -559 4 -449 -560 25 -450 -561 29 -451 -562 5 -452 -563 9 -453 -564 28 -454 -565 35 -455 -566 26 -456 -567 22 -457 -568 39 -458 -569 13 -459 -570 50 -460 -571 37 -461 -572 14 -462 -573 26 -463 -574 49 -464 -575 23 -465 -576 44 -466 -577 2 -4...
output:
50 99 -493 -604 -5700576 -8526912 -492 -603 -5679394 -8495228 -491 -602 -5658212 -8463544 -490 -601 -5637030 -8431860 -489 -600 -5615848 -8400176 -488 -599 -5594666 -8368492 -487 -598 -5573484 -8336808 -486 -597 -5552302 -8305124 -485 -596 -5531120 -8273440 -484 -595 -5509938 -8241756 -483 -594 -548...
result:
ok ok Sum L = 4950
Test #18:
score: 0
Accepted
time: 1ms
memory: 3540kb
input:
50 -142 0 48 -143 1 22 -144 2 45 -145 3 9 -146 4 36 -147 5 46 -148 6 26 -149 7 26 -150 8 9 -151 9 19 -152 10 22 -153 11 14 -154 12 8 -155 13 20 -156 14 41 -157 15 47 -158 16 22 -159 17 50 -160 18 3 -161 19 12 -162 20 15 -163 21 32 -164 22 46 -165 23 45 -166 24 3 -167 25 27 -168 26 33 -169 27 17 -170...
output:
50 99 -191 49 -14298683 -21387946 -190 48 -14192059 -21228458 -189 47 -14085435 -21068970 -188 46 -13978811 -20909482 -187 45 -13872187 -20749994 -186 44 -13765563 -20590506 -185 43 -13658939 -20431018 -184 42 -13552315 -20271530 -183 41 -13445691 -20112042 -182 40 -13339067 -19952554 -181 39 -13232...
result:
ok ok Sum L = 4950
Test #19:
score: 0
Accepted
time: 1ms
memory: 3412kb
input:
12 1000 1000 50 1000 -1000 50 1000 999 50 999 1000 50 999 -1000 50 -999 1000 50 1000 -999 50 -999 -1000 50 -1000 1000 50 -1000 -1000 50 -1000 -999 50 -1000 999 50
output:
50 23 -1000 1000 -106623881 -159487822 -1000 999 -106581160 -159423920 -999 1000 -106559978 -159392236 -1000 -999 -21224602 -31747724 -1000 -1000 -21181881 -31683822 -999 -1000 -21117978 -31588236 999 1000 21118216 31588592 1000 1000 21182119 31684178 1000 999 21224840 31748080 999 -1000 106560216 1...
result:
ok ok Sum L = 1150
Test #20:
score: 0
Accepted
time: 1ms
memory: 3384kb
input:
4 1000 1000 50 1000 -1000 50 -1000 1000 50 -1000 -1000 50
output:
50 7 -1000 1000 -106623881 -159487822 -1000 -1000 -21181881 -31683822 1000 1000 21182119 31684178 1000 -1000 7 -1000 1000 -106623522 -159487285 -1000 -1000 -21181522 -31683285 1000 1000 21182478 31684715 1000 -1000 7 -1000 1000 -106623163 -159486748 -1000 -1000 -21181163 -31682748 1000 1000 21182837...
result:
ok ok Sum L = 350
Extra Test:
score: 0
Extra Test Passed