QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#473005 | #8873. Keys | PetroTarnavskyi | AC ✓ | 225ms | 31948kb | C++23 | 3.7kb | 2024-07-11 20:52:59 | 2024-07-11 20:53:00 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;
const int N = 100'447;
VI g[N];
bool used[N];
int from[N];
int p[N];
map<PII, int> mp;
void dfs1(int v)
{
used[v] = true;
for (auto to : g[v])
{
if (!used[to])
{
from[to] = v;
dfs1(to);
}
}
}
int dfs2(int v, int par = -1)
{
used[v] = 1;
p[v] = par;
for (auto to : g[v])
{
if (to == par)
continue;
if (to == 1)
return v;
if(used[to])
continue;
int res = dfs2(to, v);
if (res != -1)
return res;
}
return -1;
}
void printKeys(const VI& v)
{
FOR (i, 0, SZ(v))
{
if (i)
cout << ' ';
cout << v[i];
}
cout << '\n';
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
FOR (i, 0, m)
{
int a, b;
cin >> a >> b;
mp[{a, b}] = i;
mp[{b, a}] = i;
g[a].PB(b);
g[b].PB(a);
}
used[1] = true;
dfs1(0);
int cnt = 0;
for (auto to : g[1])
{
if (used[to])
cnt++;
}
if (cnt >= 2)
{
int u = -1;
for (auto to : g[1])
{
if (used[to])
u = to;
}
int U = u;
VI path = {1, u};
while (u != 0)
{
u = from[u];
path.PB(u);
}
set<int> marichka;
FOR (i, 0, SZ(path) - 1)
marichka.insert(mp[{path[i], path[i + 1]}]);
VI zenyk;
FOR (i, 0, m)
if (!marichka.count(i))
zenyk.PB(i);
reverse(ALL(path));
VI mar(ALL(marichka));
printKeys(mar);
printKeys(zenyk);
FOR (i, 1, SZ(path))
{
cout << "MOVE " << path[i] << '\n';
if (i + 1 != SZ(path))
cout << "DROP " << mp[{path[i - 1], path[i]}] << '\n';
}
cout << "DONE\n";
path.clear();
int v = -1;
for (auto to : g[1])
{
if (used[to] && to != U)
v = to;
}
path = {1, v};
while (v != 0)
{
v = from[v];
path.PB(v);
}
FOR (i, 0, SZ(path) - 1)
{
cout << "GRAB\n";
cout << "MOVE " << path[i + 1] << '\n';
}
cout << "DONE\n";
}
else
{
if (cnt == 0)
{
cout << "No solution\n";
return 0;
}
int u = -1;
for (auto to : g[1])
{
if (used[to])
u = to;
}
int U = u;
VI path = {1, u};
while (u != 0)
{
u = from[u];
path.PB(u);
}
reverse(ALL(path));
FOR(i, 0, n)
used[i] = false;
int v = dfs2(1);
if (v == -1)
{
cout << "No solution\n";
return 0;
}
int V = v;
VI cycle = { 1, v };
while (v != 1)
{
v = p[v];
cycle.PB(v);
}
reverse(ALL(cycle));
set<int> marichka;
FOR (i, 0, SZ(path) - 1)
marichka.insert(mp[{path[i], path[i + 1]}]);
marichka.insert(mp[{1, V}]);
VI zenyk;
FOR (i, 0, m)
if (!marichka.count(i))
zenyk.PB(i);
VI mar(ALL(marichka));
printKeys(mar);
printKeys(zenyk);
FOR (i, 1, SZ(path))
{
cout << "MOVE " << path[i] << '\n';
if (i + 1 != SZ(path))
cout << "DROP " << mp[{path[i - 1], path[i]}] << '\n';
}
cout << "MOVE " << V << '\n';
cout << "DROP " << mp[{1, U}] << '\n';
cout << "MOVE " << 1 << '\n';
cout << "DONE\n";
FOR (i, 1, SZ(cycle) - 1)
{
cout << "MOVE " << cycle[i] << '\n';
}
cout << "GRAB\n";
RFOR (i, SZ(cycle) - 2, 0)
cout << "MOVE " << cycle[i] << '\n';
RFOR (i, SZ(path) - 1, 0)
{
cout << "GRAB\n";
cout << "MOVE " << path[i] << '\n';
}
cout << "DONE\n";
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 107ms
memory: 22732kb
input:
100000 100000 23318 40203 97982 61157 60398 86095 58324 78522 28830 15221 65885 58978 88701 79733 60488 97069 18196 67504 53341 92581 41374 31350 38622 72661 83410 44870 47326 8073 98347 37592 6260 85798 28852 71221 50180 3244 64489 93594 78096 7442 17696 59981 22755 17291 17870 81187 35524 29465 22...
output:
7 18 33 35 36 101 140 145 187 188 193 210 248 299 308 331 338 348 405 410 428 433 437 443 462 479 498 505 537 538 579 589 594 608 613 632 646 652 697 710 738 785 792 804 827 836 843 882 908 929 936 952 1038 1047 1052 1111 1129 1132 1194 1213 1249 1284 1298 1315 1320 1321 1325 1369 1390 1397 1401 140...
result:
ok good job, 20639 instruction(s)
Test #2:
score: 0
Accepted
time: 108ms
memory: 21440kb
input:
50000 100000 8934 28735 44226 12238 17786 15795 13217 27239 168 16295 550 15556 16441 41473 36979 35662 5444 33264 26116 48547 32991 35682 15764 44379 12428 45701 47650 4749 32595 21554 40428 36364 41567 14621 3849 33959 43468 46279 48666 11408 3325 20704 25461 14749 47526 49245 33711 19577 13605 43...
output:
0 1 2 4 5 6 9 10 12 17 19 20 24 26 30 31 33 34 36 37 38 39 40 43 44 45 47 48 49 50 52 53 54 55 57 58 59 60 61 62 66 67 68 69 71 73 76 77 79 80 81 82 86 87 88 91 92 93 94 95 96 97 98 101 102 103 104 105 106 108 109 110 111 112 113 114 117 118 120 121 122 125 126 129 131 132 133 134 136 138 139 140 14...
result:
ok good job, 82851 instruction(s)
Test #3:
score: 0
Accepted
time: 195ms
memory: 27568kb
input:
100000 100000 25942 82376 88672 78819 18680 79879 67017 29864 43795 42855 7573 47211 33582 81171 12735 62529 65617 20494 99853 41155 78124 82179 38806 81035 57275 6802 50707 33443 33953 4519 91953 55970 59249 62761 48557 65743 71493 80407 90878 54712 66231 20900 21622 66923 94531 11951 54879 92804 5...
output:
0 1 2 3 4 5 7 11 13 14 16 17 18 19 21 22 26 27 31 34 35 37 40 41 42 44 45 46 47 50 51 56 58 62 64 65 66 67 72 73 74 75 76 77 79 80 82 83 84 85 87 88 89 90 92 93 94 95 96 97 99 101 103 104 106 109 110 112 113 114 116 117 119 121 122 123 125 126 128 130 132 133 134 135 136 139 142 144 145 146 147 148 ...
result:
ok good job, 299997 instruction(s)
Test #4:
score: 0
Accepted
time: 225ms
memory: 29320kb
input:
100000 100000 21864 56883 52947 45601 74935 69509 94478 26883 4033 18901 13136 47602 57282 96987 1689 58102 77156 35075 95629 47175 5915 19979 71495 48121 91235 85213 69319 43824 88116 6683 42155 72450 15251 23971 28359 85564 88246 94015 27333 69498 26663 81965 31007 91728 69773 34777 42347 72107 89...
output:
0 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 10...
result:
ok good job, 399987 instruction(s)
Test #5:
score: 0
Accepted
time: 194ms
memory: 28988kb
input:
100000 100000 1579 36634 55021 87121 61247 53504 26526 11501 63096 95355 26157 54097 22547 72337 53502 93653 10336 58493 18020 41208 7269 2318 12039 94961 70947 16210 46822 1274 33785 1813 10779 40529 77491 71330 9272 95406 36277 69039 33374 7524 83196 20806 96206 89860 86304 59579 95435 52196 80968...
output:
0 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 31 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 53 54 55 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 96 97 98 99 100 101 102 103 104 105 106 ...
result:
ok good job, 200017 instruction(s)
Test #6:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
6 6 0 2 2 3 3 1 3 4 4 5 1 5
output:
0 1 3 4 5 2 MOVE 2 DROP 0 MOVE 3 DROP 1 MOVE 4 DROP 3 MOVE 5 DROP 4 MOVE 1 DONE GRAB MOVE 3 GRAB MOVE 2 GRAB MOVE 0 DONE
result:
ok good job, 17 instruction(s)
Test #7:
score: 0
Accepted
time: 1ms
memory: 3632kb
input:
6 6 0 2 2 3 3 1 1 4 4 5 1 5
output:
0 1 2 5 3 4 MOVE 2 DROP 0 MOVE 3 DROP 1 MOVE 1 MOVE 5 DROP 2 MOVE 1 DONE MOVE 4 MOVE 5 GRAB MOVE 4 MOVE 1 GRAB MOVE 3 GRAB MOVE 2 GRAB MOVE 0 DONE
result:
ok good job, 21 instruction(s)
Test #8:
score: 0
Accepted
time: 108ms
memory: 22792kb
input:
100000 100000 96367 66531 65295 71645 67296 93287 73673 40112 15826 61132 89088 31681 50727 38751 7202 84213 59585 77793 48336 3706 17614 32412 6411 36116 80130 50904 81086 20756 69676 50485 46054 28686 16875 11587 91878 86414 12128 41724 69733 78314 87279 80436 57326 95934 26572 60051 2769 85752 15...
output:
16 23 39 54 85 103 121 146 147 177 183 227 236 242 243 255 279 306 311 314 323 325 327 342 406 437 440 443 449 455 483 526 554 567 576 596 614 641 647 651 657 667 685 690 737 745 793 806 807 816 834 835 838 844 846 847 875 876 883 894 918 941 943 944 946 983 984 991 993 997 1033 1037 1045 1048 1063 ...
result:
ok good job, 25037 instruction(s)
Test #9:
score: 0
Accepted
time: 156ms
memory: 25804kb
input:
100000 100000 10014 30317 91383 38616 44018 69738 67567 14439 94645 77295 40683 36981 93253 77191 86464 17901 9306 64146 77493 92538 73062 26034 41936 5045 43534 12176 81788 12494 51574 64920 79813 936 81999 67801 60001 96187 61237 45643 81878 58084 41735 16898 11958 65746 51947 96855 72637 87194 71...
output:
0 4 6 9 11 15 16 17 19 24 26 29 34 35 36 37 38 39 40 41 44 47 54 55 56 58 60 62 63 68 72 73 74 76 80 81 82 84 87 88 89 91 92 93 94 96 99 104 105 106 108 109 114 115 118 119 120 121 124 125 126 127 128 129 132 133 135 136 138 140 142 143 144 150 153 154 155 157 159 160 161 163 166 167 168 169 173 174...
result:
ok good job, 200001 instruction(s)
Test #10:
score: 0
Accepted
time: 120ms
memory: 21692kb
input:
50000 100000 24539 6119 20751 35924 41982 48393 19912 32252 10409 28344 16342 33219 1887 8519 21267 26408 8705 10970 2657 17850 39993 2645 512 27373 15091 23151 12486 45982 48476 4490 25329 15083 7662 42457 3308 3722 4529 42388 24030 42893 24228 9162 38184 41052 9096 16089 4324 11034 26951 33431 270...
output:
0 1 3 4 6 8 9 10 11 13 16 17 18 23 27 28 31 32 34 36 39 45 48 49 50 51 54 55 56 57 58 61 62 64 65 68 69 71 72 74 85 86 89 90 91 94 97 98 99 100 102 106 108 109 111 113 115 118 119 120 122 124 125 129 130 132 133 134 135 138 139 140 141 144 146 147 148 149 150 151 152 154 156 157 158 159 160 164 165 ...
result:
ok good job, 56081 instruction(s)
Test #11:
score: 0
Accepted
time: 109ms
memory: 23712kb
input:
100000 100000 43296 75273 85441 62496 89990 49908 73020 129 55990 71803 84461 36667 88524 92277 57523 90585 61215 94569 67755 68868 12382 91067 84640 1421 10362 56957 54388 15787 98562 57954 57458 7730 90559 76725 10535 67001 37969 90538 63009 83781 33040 174 28995 25391 42150 72884 48377 68701 7704...
output:
7 9 18 39 47 62 63 71 81 87 104 124 154 161 169 196 206 229 231 253 258 260 261 279 286 287 288 289 318 323 325 330 334 337 372 387 399 403 408 415 432 444 476 484 491 505 511 515 519 555 563 567 581 585 603 605 610 617 642 646 654 668 670 671 673 679 691 698 710 723 754 759 765 780 791 797 800 828 ...
result:
ok good job, 59173 instruction(s)
Test #12:
score: 0
Accepted
time: 98ms
memory: 20908kb
input:
50000 100000 7568 36646 1279 47292 45650 35409 46841 16671 47440 40391 27528 17631 10548 26844 23545 14620 14511 23071 13025 37478 1923 48560 6122 30106 28548 36103 9215 36285 37710 44617 3674 49875 14022 16799 44476 30381 33114 30895 41787 37779 19820 47557 7937 4087 2576 2981 19278 36043 6340 3419...
output:
12 15 18 21 22 35 43 49 55 57 91 95 105 113 129 140 143 152 167 168 174 180 189 191 196 198 199 201 215 216 218 221 228 230 238 265 276 284 307 308 315 321 327 331 346 353 361 363 375 386 418 419 421 433 448 450 452 461 478 482 498 520 521 527 529 532 545 558 573 579 582 589 590 593 602 608 623 643 ...
result:
ok good job, 42007 instruction(s)
Test #13:
score: 0
Accepted
time: 166ms
memory: 27668kb
input:
100000 100000 86322 4929 83579 61717 81028 93863 63624 56270 52901 75158 54370 34740 58954 62029 97574 74084 32946 39229 4694 95648 22560 76996 79300 91701 99942 32414 68575 29471 58051 52619 69874 19847 12767 11792 74151 54115 25 82313 94428 47942 58029 93563 89788 29043 70700 79708 20195 35110 351...
output:
1 3 7 8 9 13 15 16 17 19 21 22 24 25 28 29 30 31 36 37 39 41 43 44 47 48 49 50 51 54 55 59 64 70 71 73 74 76 78 79 80 82 83 85 86 90 97 101 104 105 106 107 110 112 114 115 118 120 123 125 126 127 134 138 143 144 148 150 152 153 156 157 158 159 162 163 165 166 168 170 171 175 176 177 179 180 183 185 ...
result:
ok good job, 299999 instruction(s)
Test #14:
score: 0
Accepted
time: 216ms
memory: 31948kb
input:
100000 100000 25428 37272 69619 7282 64587 18392 24381 57301 54320 20485 17236 59526 30823 38757 55343 17370 37512 58190 86473 19428 30287 35049 10303 29575 44114 62530 62330 49078 82698 70083 71507 48140 11831 88428 3173 16351 15822 7562 77244 22730 38140 96265 78005 44175 20548 8320 39079 10796 83...
output:
0 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 10...
result:
ok good job, 399993 instruction(s)
Test #15:
score: 0
Accepted
time: 110ms
memory: 27484kb
input:
100000 100000 10889 73894 28668 13203 98139 70161 1044 5038 47917 31269 58227 54508 26143 15200 46703 96821 51030 9669 98391 36506 27411 30543 5988 84867 58309 98558 67523 58507 71133 50142 56482 50601 97335 29657 81621 28543 38313 68151 46162 31389 30858 76334 48708 20205 6111 47722 52359 39481 645...
output:
633 639 2251 4444 5006 5292 5592 6842 8127 8320 9874 10626 11921 12241 12631 12822 13365 15098 15102 15490 16368 16492 17821 19810 19865 20488 20765 20815 20959 21225 21726 22473 28287 28414 31335 31507 31891 32502 34089 34107 35996 36007 36446 36620 37816 41577 41819 45563 47081 47177 47780 53432 5...
result:
ok good job, 200199 instruction(s)
Test #16:
score: 0
Accepted
time: 1ms
memory: 3528kb
input:
6 6 0 2 2 3 3 1 1 5 2 4 3 4
output:
No solution
result:
ok no solution
Test #17:
score: 0
Accepted
time: 96ms
memory: 19944kb
input:
50000 100000 26144 7421 22412 44494 29727 15433 49590 24000 44200 24509 37641 22526 23764 19318 8924 18734 26213 42867 11997 29991 21761 5388 45970 13904 20943 43174 16307 22885 26999 22799 41360 41456 25911 8522 35863 33750 46384 21531 21281 8834 15465 49013 1753 4004 27082 15982 19334 27615 33954 ...
output:
No solution
result:
ok no solution
Test #18:
score: 0
Accepted
time: 101ms
memory: 22204kb
input:
90000 100000 64261 74711 3299 89019 86241 18036 20799 48883 20053 72155 61408 44131 2243 74042 76172 5660 71753 15465 14846 30249 87138 73873 60899 62854 68202 28401 25560 33368 34094 75934 26244 45318 56438 50859 17557 74836 27193 84062 80223 8263 19255 46960 89294 7521 63921 852 83066 1187 81691 4...
output:
No solution
result:
ok no solution
Test #19:
score: 0
Accepted
time: 104ms
memory: 21644kb
input:
80000 99999 39119 4959 79093 57828 22618 54434 19532 65500 70312 13855 1851 13852 59001 71101 47059 65915 66225 24764 72168 58158 61158 31691 4393 33815 65233 34904 54222 39966 71200 74623 7657 77656 74506 32078 46352 7090 56533 50975 48596 6918 38663 36592 3485 70779 68511 51111 50834 25116 16186 2...
output:
No solution
result:
ok no solution
Test #20:
score: 0
Accepted
time: 101ms
memory: 23344kb
input:
100000 99999 49345 76110 2798 86271 57038 171 77955 15337 19296 48682 98349 5586 31051 49709 29280 27554 35162 52474 25359 81583 69885 46484 25451 32306 33480 72015 1367 90132 91794 22392 54238 86888 54749 9873 20459 26835 47752 90888 77221 48293 88587 256 24236 58681 4801 8895 29926 32488 47889 255...
output:
No solution
result:
ok no solution
Test #21:
score: 0
Accepted
time: 1ms
memory: 3512kb
input:
6 6 0 1 1 2 2 3 3 4 4 5 0 5
output:
1 2 3 4 5 0 MOVE 5 DROP 5 MOVE 4 DROP 4 MOVE 3 DROP 3 MOVE 2 DROP 2 MOVE 1 DONE GRAB MOVE 0 DONE
result:
ok good job, 13 instruction(s)
Test #22:
score: 0
Accepted
time: 96ms
memory: 22540kb
input:
100000 100000 59828 64708 47750 16573 57769 81309 99088 79554 69563 87704 77880 38685 82767 50190 69199 35860 57542 75312 81796 99850 33543 99431 56817 78988 68644 9817 40018 32389 78233 43850 51782 70539 97258 21202 36292 91807 94611 42699 4237 7706 97296 17899 82467 22237 545 76141 75385 23587 129...
output:
No solution
result:
ok no solution
Test #23:
score: 0
Accepted
time: 128ms
memory: 21476kb
input:
50000 100000 14198 3429 21041 27019 19584 19711 39287 34721 15399 34050 11683 31085 13955 46499 25087 11616 19485 946 36235 37467 33136 7703 2361 6714 5763 38639 47041 27135 48735 7749 17747 36327 30830 1522 45507 8282 46226 22455 9592 19737 10008 20723 7119 20392 6430 43960 43822 39822 21097 11434 ...
output:
3 5 6 7 8 13 14 15 16 17 18 19 21 24 25 26 27 28 30 31 32 33 34 36 37 38 40 41 47 48 49 50 51 53 54 55 56 57 59 62 64 65 66 67 69 70 71 72 74 75 76 78 79 83 86 89 90 93 94 96 98 100 101 102 104 105 106 107 108 109 110 112 114 115 117 120 122 124 126 130 133 134 136 138 141 142 145 146 147 149 150 15...
result:
ok good job, 88837 instruction(s)
Test #24:
score: 0
Accepted
time: 107ms
memory: 23124kb
input:
90000 100000 70015 24995 73200 87248 12741 75391 34774 22943 21965 53886 1683 18908 54010 88101 39661 54904 11072 62774 48600 64239 20437 85037 54989 8249 14077 74956 44570 32008 27854 72613 89714 70086 21262 1153 2696 9930 67044 74871 36017 2386 10562 85960 32615 76055 1792 74732 36996 14729 15301 ...
output:
No solution
result:
ok no solution
Test #25:
score: 0
Accepted
time: 115ms
memory: 21428kb
input:
40000 100000 2078 4393 29204 30505 29433 14568 15183 32906 20225 19309 21922 9700 31026 31286 7627 7349 33842 1908 17471 16058 13786 36351 33519 10984 14645 23624 30419 11149 15925 25328 5549 24013 18809 27531 32587 38623 11672 7833 19162 25199 32748 31258 11833 31833 26558 11203 24694 8796 29328 19...
output:
0 1 2 3 4 5 7 8 9 10 11 12 13 14 15 16 18 19 20 21 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 47 48 49 51 52 53 54 55 56 57 58 59 60 62 63 64 65 66 67 68 69 70 72 73 74 75 76 78 80 81 82 83 84 85 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109...
result:
ok good job, 94737 instruction(s)
Test #26:
score: 0
Accepted
time: 133ms
memory: 22164kb
input:
60000 100000 41782 59837 56864 23608 29860 43226 20509 19621 13947 2214 58705 33 9631 17559 52626 17291 4051 39368 45882 40381 20032 16705 49072 47635 58180 35649 4143 36217 10237 50827 40642 15676 33763 53910 31325 39360 43691 31911 56426 47740 28181 36633 16943 11090 34059 53313 43159 22495 41289 ...
output:
0 1 4 5 8 11 12 17 18 19 20 23 25 27 29 30 31 32 37 39 40 42 44 46 47 49 51 54 55 56 58 61 65 68 69 70 71 73 75 78 81 82 84 87 90 94 97 99 100 102 104 106 107 108 109 111 113 114 115 118 120 121 122 125 126 127 128 130 131 132 133 134 135 136 137 138 140 141 142 143 144 146 147 149 150 151 152 154 1...
result:
ok good job, 99345 instruction(s)