QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#472849 | #8873. Keys | PetroTarnavskyi# | WA | 265ms | 29340kb | C++20 | 3.7kb | 2024-07-11 19:52:29 | 2024-07-11 19:52:29 |
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)
{
p[v] = par;
for (auto to : g[v])
{
if (to == par)
continue;
if (to == 1)
return v;
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)
{
int k = mp[{path[i], path[i + 1]}];
if (marichka.count(k))
cout << "GRAB\n";
cout << "MOVE " << path[i + 1] << '\n';
}
cout << "DONE\n";
}
else
{
if (cnt == 0)
{
cout << "No solution\n";
return 0;
}
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));
int u = -1;
for (auto to : g[1])
{
if (used[to])
u = to;
}
VI path = {1, u};
while (u != 0)
{
u = from[u];
path.PB(u);
}
reverse(ALL(path));
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 106ms
memory: 22700kb
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, 20435 instruction(s)
Test #2:
score: 0
Accepted
time: 120ms
memory: 21480kb
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, 82385 instruction(s)
Test #3:
score: 0
Accepted
time: 196ms
memory: 27648kb
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, 256344 instruction(s)
Test #4:
score: 0
Accepted
time: 265ms
memory: 29340kb
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, 399984 instruction(s)
Test #5:
score: 0
Accepted
time: 199ms
memory: 28956kb
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, 194835 instruction(s)
Test #6:
score: 0
Accepted
time: 0ms
memory: 3492kb
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 MOVE 3 GRAB MOVE 2 GRAB MOVE 0 DONE
result:
ok good job, 16 instruction(s)
Test #7:
score: -100
Wrong Answer
time: 0ms
memory: 3720kb
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 0 MOVE 1 DONE MOVE 4 MOVE 5 GRAB MOVE 4 MOVE 1 GRAB MOVE 3 GRAB MOVE 2 GRAB MOVE 0 DONE
result:
wrong answer Alice doesn't have the key 0 right now, so she can't drop that key