#include "Anthony.h"
#include <queue>
#include <utility>
#include <vector>
namespace {
using std::vector;
} // namespace
std::vector<int> Mark(int N, int M, int A, int B,
std::vector<int> U, std::vector<int> V) {
vector<vector<int>> G(N);
for (int i = 0; i < M; ++i) {
G[U[i]].push_back(i);
G[V[i]].push_back(i);
}
std::queue<int> que;
vector<int> dist(N, N);
vector<int> colors(N, -1);
dist[0] = 0;
que.push(0);
for (; !que.empty(); ) {
const int u = que.front();
que.pop();
for (const int i : G[u]) {
const int v = U[i] ^ V[i] ^ u;
if (dist[v] > dist[u] + 1) {
dist[v] = dist[u] + 1;
que.push(v);
if (A == 2) {
if (u == 0) {
colors[v] = 0;
} else if (G[u].size() >= 3) {
colors[v] = ("010011"[colors[u]] == '0') ? 1 : 0;
} else {
colors[v] = (colors[u] + 1) % 6;
}
}
}
}
}
vector<int> x(M, -1);
for (int i = 0; i < M; ++i) {
int u = U[i], v = V[i];
if (dist[u] > dist[v]) {
std::swap(u, v);
}
if (A == 2) {
x[i] = "010011"[colors[v]] - '0';
} else {
x[i] = dist[u] % 3;
}
}
return x;
}
#include "Catherine.h"
#include <assert.h>
#include <algorithm>
#include <string>
#include <vector>
namespace {
using std::string;
int A, B;
int last = -1;
bool known = false;
string seq = "";
} // namespace
void Init(int A, int B) {
::A = A;
::B = B;
}
int Move(std::vector<int> y) {
int ans = -2;
auto yy = y;
if (last != -1) {
++yy[last];
}
if (A == 2) {
int deg = 0;
for (int k = 0; k < 2; ++k) {
deg += yy[k];
}
if (deg == 2) {
if (known) {
assert(std::count(y.begin(), y.end(), 1) == 1);
ans = std::find(y.begin(), y.end(), 1) - y.begin();
} else {
for (int k = 0; k < 2; ++k) {
seq += string(y[k], static_cast<char>('0' + k));
}
if (seq.size() == 5) {
bool rev = false;
for (int rot = 0; rot < 6; ++rot) {
if (seq == string("010011010011").substr(rot, 5)) {
rev = true;
}
}
known = true;
if (rev) {
ans = -1;
} else {
assert(std::count(y.begin(), y.end(), 1) == 1);
ans = std::find(y.begin(), y.end(), 1) - y.begin();
}
} else {
ans = seq.back() - '0';
}
}
} else {
known = true;
assert(std::count(yy.begin(), yy.end(), 1) == 1);
ans = std::find(yy.begin(), yy.end(), 1) - yy.begin();
if (ans == last) {
ans = -1;
}
}
} else {
int flag = 0;
for (int k = 0; k < 3; ++k) {
if (yy[k] > 0) {
flag |= 1 << k;
}
}
switch (flag) {
case 0b001: case 0b011: ans = 0; break;
case 0b010: case 0b110: ans = 1; break;
case 0b100: case 0b101: ans = 2; break;
default: assert(false);
}
}
if (ans != -1) {
last = ans;
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
67 ms |
15316 KB |
Output is correct |
2 |
Correct |
9 ms |
908 KB |
Output is correct |
3 |
Correct |
50 ms |
14780 KB |
Output is correct |
4 |
Correct |
74 ms |
16320 KB |
Output is correct |
5 |
Correct |
72 ms |
16380 KB |
Output is correct |
6 |
Correct |
77 ms |
15112 KB |
Output is correct |
7 |
Correct |
67 ms |
15196 KB |
Output is correct |
8 |
Correct |
77 ms |
15732 KB |
Output is correct |
9 |
Correct |
77 ms |
15868 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
67 ms |
15316 KB |
Output is correct |
2 |
Correct |
9 ms |
908 KB |
Output is correct |
3 |
Correct |
50 ms |
14780 KB |
Output is correct |
4 |
Correct |
74 ms |
16320 KB |
Output is correct |
5 |
Correct |
72 ms |
16380 KB |
Output is correct |
6 |
Correct |
77 ms |
15112 KB |
Output is correct |
7 |
Correct |
67 ms |
15196 KB |
Output is correct |
8 |
Correct |
77 ms |
15732 KB |
Output is correct |
9 |
Correct |
77 ms |
15868 KB |
Output is correct |
10 |
Correct |
49 ms |
12912 KB |
Output is correct |
11 |
Correct |
51 ms |
13040 KB |
Output is correct |
12 |
Correct |
50 ms |
13096 KB |
Output is correct |
13 |
Correct |
55 ms |
13080 KB |
Output is correct |
14 |
Correct |
51 ms |
13304 KB |
Output is correct |
15 |
Correct |
65 ms |
13552 KB |
Output is correct |
16 |
Correct |
65 ms |
15860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
53 ms |
12924 KB |
Output is correct |
2 |
Correct |
8 ms |
792 KB |
Output is correct |
3 |
Correct |
45 ms |
12548 KB |
Output is correct |
4 |
Correct |
72 ms |
14196 KB |
Output is correct |
5 |
Correct |
71 ms |
14340 KB |
Output is correct |
6 |
Correct |
52 ms |
12796 KB |
Output is correct |
7 |
Correct |
62 ms |
12768 KB |
Output is correct |
8 |
Correct |
70 ms |
13564 KB |
Output is correct |
9 |
Correct |
65 ms |
13620 KB |
Output is correct |
10 |
Correct |
61 ms |
13260 KB |
Output is correct |
11 |
Correct |
60 ms |
13308 KB |
Output is correct |
12 |
Correct |
60 ms |
13308 KB |
Output is correct |
13 |
Correct |
63 ms |
13300 KB |
Output is correct |
14 |
Correct |
74 ms |
13556 KB |
Output is correct |
15 |
Correct |
67 ms |
13556 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
53 ms |
12924 KB |
Output is correct |
2 |
Correct |
8 ms |
792 KB |
Output is correct |
3 |
Correct |
45 ms |
12548 KB |
Output is correct |
4 |
Correct |
72 ms |
14196 KB |
Output is correct |
5 |
Correct |
71 ms |
14340 KB |
Output is correct |
6 |
Correct |
52 ms |
12796 KB |
Output is correct |
7 |
Correct |
62 ms |
12768 KB |
Output is correct |
8 |
Correct |
70 ms |
13564 KB |
Output is correct |
9 |
Correct |
65 ms |
13620 KB |
Output is correct |
10 |
Correct |
61 ms |
13260 KB |
Output is correct |
11 |
Correct |
60 ms |
13308 KB |
Output is correct |
12 |
Correct |
60 ms |
13308 KB |
Output is correct |
13 |
Correct |
63 ms |
13300 KB |
Output is correct |
14 |
Correct |
74 ms |
13556 KB |
Output is correct |
15 |
Correct |
67 ms |
13556 KB |
Output is correct |
16 |
Correct |
47 ms |
11336 KB |
Output is correct |
17 |
Correct |
53 ms |
11256 KB |
Output is correct |
18 |
Correct |
48 ms |
11256 KB |
Output is correct |
19 |
Correct |
52 ms |
11160 KB |
Output is correct |
20 |
Correct |
57 ms |
11688 KB |
Output is correct |
21 |
Correct |
60 ms |
11504 KB |
Output is correct |
22 |
Correct |
64 ms |
13684 KB |
Output is correct |
23 |
Correct |
56 ms |
11256 KB |
Output is correct |
24 |
Correct |
55 ms |
11224 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
1044 KB |
Output is correct |
2 |
Correct |
8 ms |
1032 KB |
Output is correct |
3 |
Correct |
10 ms |
1116 KB |
Output is correct |
4 |
Correct |
10 ms |
1036 KB |
Output is correct |
5 |
Correct |
10 ms |
1112 KB |
Output is correct |
6 |
Correct |
10 ms |
1044 KB |
Output is correct |
7 |
Correct |
10 ms |
1136 KB |
Output is correct |
8 |
Correct |
10 ms |
1164 KB |
Output is correct |
9 |
Correct |
10 ms |
1036 KB |
Output is correct |
10 |
Correct |
10 ms |
1044 KB |
Output is correct |
11 |
Correct |
10 ms |
1172 KB |
Output is correct |
12 |
Correct |
10 ms |
1112 KB |
Output is correct |
13 |
Correct |
10 ms |
1144 KB |
Output is correct |
14 |
Correct |
10 ms |
1172 KB |
Output is correct |
15 |
Correct |
11 ms |
1092 KB |
Output is correct |
16 |
Correct |
11 ms |
1112 KB |
Output is correct |
17 |
Correct |
10 ms |
1216 KB |
Output is correct |
18 |
Correct |
10 ms |
1172 KB |
Output is correct |
19 |
Correct |
10 ms |
1116 KB |
Output is correct |
20 |
Correct |
10 ms |
1164 KB |
Output is correct |
21 |
Correct |
10 ms |
1044 KB |
Output is correct |
22 |
Correct |
10 ms |
1164 KB |
Output is correct |
23 |
Correct |
10 ms |
1144 KB |
Output is correct |
24 |
Correct |
10 ms |
1116 KB |
Output is correct |
25 |
Correct |
11 ms |
908 KB |
Output is correct |
26 |
Correct |
10 ms |
1036 KB |
Output is correct |
27 |
Correct |
10 ms |
1268 KB |
Output is correct |
28 |
Correct |
10 ms |
1144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
11132 KB |
Output is correct |
2 |
Correct |
57 ms |
11644 KB |
Output is correct |
3 |
Correct |
9 ms |
780 KB |
Output is correct |
4 |
Correct |
43 ms |
11100 KB |
Output is correct |
5 |
Correct |
65 ms |
12196 KB |
Output is correct |
6 |
Correct |
64 ms |
12164 KB |
Output is correct |
7 |
Correct |
50 ms |
11276 KB |
Output is correct |
8 |
Correct |
51 ms |
11368 KB |
Output is correct |
9 |
Correct |
64 ms |
12164 KB |
Output is correct |
10 |
Correct |
68 ms |
12148 KB |
Output is correct |
11 |
Correct |
67 ms |
12148 KB |
Output is correct |
12 |
Correct |
68 ms |
12072 KB |
Output is correct |
13 |
Correct |
72 ms |
12200 KB |
Output is correct |
14 |
Correct |
67 ms |
12148 KB |
Output is correct |
15 |
Correct |
61 ms |
12148 KB |
Output is correct |
16 |
Correct |
64 ms |
12284 KB |
Output is correct |
17 |
Correct |
61 ms |
11912 KB |
Output is correct |
18 |
Correct |
60 ms |
11908 KB |
Output is correct |
19 |
Correct |
60 ms |
11900 KB |
Output is correct |
20 |
Correct |
69 ms |
11892 KB |
Output is correct |
21 |
Correct |
61 ms |
12020 KB |
Output is correct |
22 |
Correct |
75 ms |
11928 KB |
Output is correct |
23 |
Correct |
49 ms |
11108 KB |
Output is correct |
24 |
Correct |
50 ms |
11264 KB |
Output is correct |
25 |
Correct |
52 ms |
11132 KB |
Output is correct |
26 |
Correct |
59 ms |
11388 KB |
Output is correct |
27 |
Correct |
63 ms |
11508 KB |
Output is correct |
28 |
Correct |
63 ms |
11636 KB |
Output is correct |
29 |
Correct |
56 ms |
11780 KB |
Output is correct |
30 |
Correct |
60 ms |
11644 KB |
Output is correct |
31 |
Correct |
57 ms |
11376 KB |
Output is correct |
32 |
Correct |
54 ms |
11128 KB |
Output is correct |
33 |
Correct |
57 ms |
11260 KB |
Output is correct |
34 |
Correct |
51 ms |
11268 KB |
Output is correct |
35 |
Correct |
59 ms |
11516 KB |
Output is correct |
36 |
Correct |
56 ms |
11652 KB |
Output is correct |
37 |
Correct |
60 ms |
11548 KB |
Output is correct |
38 |
Correct |
56 ms |
11536 KB |
Output is correct |
39 |
Correct |
64 ms |
11644 KB |
Output is correct |
40 |
Correct |
65 ms |
11596 KB |
Output is correct |
41 |
Correct |
69 ms |
11652 KB |
Output is correct |
42 |
Correct |
57 ms |
11800 KB |
Output is correct |
43 |
Correct |
56 ms |
11784 KB |
Output is correct |
44 |
Correct |
71 ms |
11908 KB |
Output is correct |
45 |
Correct |
67 ms |
11900 KB |
Output is correct |
46 |
Correct |
61 ms |
12028 KB |
Output is correct |
47 |
Correct |
55 ms |
11408 KB |
Output is correct |
48 |
Correct |
55 ms |
11408 KB |
Output is correct |
49 |
Correct |
57 ms |
11396 KB |
Output is correct |
50 |
Correct |
54 ms |
11768 KB |
Output is correct |
51 |
Correct |
49 ms |
11292 KB |
Output is correct |
52 |
Correct |
49 ms |
11284 KB |
Output is correct |
53 |
Correct |
52 ms |
11260 KB |
Output is correct |
54 |
Correct |
49 ms |
11284 KB |
Output is correct |
55 |
Correct |
50 ms |
11280 KB |
Output is correct |
56 |
Correct |
49 ms |
11284 KB |
Output is correct |
57 |
Correct |
50 ms |
11276 KB |
Output is correct |
58 |
Correct |
51 ms |
11396 KB |
Output is correct |
59 |
Correct |
49 ms |
11292 KB |
Output is correct |
60 |
Correct |
49 ms |
11304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
11048 KB |
Output is correct |
2 |
Correct |
54 ms |
11516 KB |
Output is correct |
3 |
Correct |
9 ms |
664 KB |
Output is correct |
4 |
Correct |
42 ms |
10880 KB |
Output is correct |
5 |
Correct |
60 ms |
12168 KB |
Output is correct |
6 |
Correct |
62 ms |
12324 KB |
Output is correct |
7 |
Correct |
50 ms |
11424 KB |
Output is correct |
8 |
Correct |
49 ms |
11296 KB |
Output is correct |
9 |
Correct |
59 ms |
12180 KB |
Output is correct |
10 |
Correct |
60 ms |
12204 KB |
Output is correct |
11 |
Correct |
60 ms |
12268 KB |
Output is correct |
12 |
Correct |
61 ms |
12156 KB |
Output is correct |
13 |
Correct |
60 ms |
12196 KB |
Output is correct |
14 |
Correct |
61 ms |
12196 KB |
Output is correct |
15 |
Correct |
61 ms |
12268 KB |
Output is correct |
16 |
Correct |
60 ms |
12200 KB |
Output is correct |
17 |
Correct |
55 ms |
11900 KB |
Output is correct |
18 |
Correct |
57 ms |
11936 KB |
Output is correct |
19 |
Correct |
57 ms |
12020 KB |
Output is correct |
20 |
Correct |
56 ms |
11928 KB |
Output is correct |
21 |
Correct |
56 ms |
11940 KB |
Output is correct |
22 |
Correct |
60 ms |
11936 KB |
Output is correct |
23 |
Correct |
47 ms |
11104 KB |
Output is correct |
24 |
Correct |
50 ms |
11224 KB |
Output is correct |
25 |
Correct |
48 ms |
11236 KB |
Output is correct |
26 |
Correct |
55 ms |
11124 KB |
Output is correct |
27 |
Correct |
55 ms |
11540 KB |
Output is correct |
28 |
Correct |
55 ms |
11832 KB |
Output is correct |
29 |
Correct |
55 ms |
11668 KB |
Output is correct |
30 |
Correct |
56 ms |
11668 KB |
Output is correct |
31 |
Correct |
48 ms |
11232 KB |
Output is correct |
32 |
Correct |
48 ms |
11012 KB |
Output is correct |
33 |
Correct |
50 ms |
11268 KB |
Output is correct |
34 |
Correct |
49 ms |
11384 KB |
Output is correct |
35 |
Correct |
55 ms |
11564 KB |
Output is correct |
36 |
Correct |
57 ms |
11540 KB |
Output is correct |
37 |
Correct |
55 ms |
11532 KB |
Output is correct |
38 |
Correct |
54 ms |
11544 KB |
Output is correct |
39 |
Correct |
56 ms |
11516 KB |
Output is correct |
40 |
Correct |
55 ms |
11640 KB |
Output is correct |
41 |
Correct |
55 ms |
11788 KB |
Output is correct |
42 |
Correct |
56 ms |
11792 KB |
Output is correct |
43 |
Correct |
56 ms |
11748 KB |
Output is correct |
44 |
Correct |
57 ms |
11900 KB |
Output is correct |
45 |
Correct |
57 ms |
11764 KB |
Output is correct |
46 |
Correct |
55 ms |
11804 KB |
Output is correct |
47 |
Correct |
59 ms |
11396 KB |
Output is correct |
48 |
Correct |
53 ms |
11408 KB |
Output is correct |
49 |
Correct |
51 ms |
11260 KB |
Output is correct |
50 |
Correct |
56 ms |
11540 KB |
Output is correct |
51 |
Correct |
49 ms |
11372 KB |
Output is correct |
52 |
Correct |
54 ms |
11284 KB |
Output is correct |
53 |
Correct |
50 ms |
11288 KB |
Output is correct |
54 |
Correct |
49 ms |
11516 KB |
Output is correct |
55 |
Correct |
49 ms |
11284 KB |
Output is correct |
56 |
Correct |
50 ms |
11280 KB |
Output is correct |
57 |
Correct |
54 ms |
11400 KB |
Output is correct |
58 |
Correct |
52 ms |
11268 KB |
Output is correct |
59 |
Correct |
49 ms |
11300 KB |
Output is correct |
60 |
Correct |
50 ms |
11292 KB |
Output is correct |