#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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
15712 KB |
Output is correct |
2 |
Correct |
1 ms |
1040 KB |
Output is correct |
3 |
Correct |
26 ms |
14908 KB |
Output is correct |
4 |
Correct |
41 ms |
16672 KB |
Output is correct |
5 |
Correct |
46 ms |
16676 KB |
Output is correct |
6 |
Correct |
32 ms |
15552 KB |
Output is correct |
7 |
Correct |
33 ms |
15428 KB |
Output is correct |
8 |
Correct |
34 ms |
16248 KB |
Output is correct |
9 |
Correct |
41 ms |
16180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
15712 KB |
Output is correct |
2 |
Correct |
1 ms |
1040 KB |
Output is correct |
3 |
Correct |
26 ms |
14908 KB |
Output is correct |
4 |
Correct |
41 ms |
16672 KB |
Output is correct |
5 |
Correct |
46 ms |
16676 KB |
Output is correct |
6 |
Correct |
32 ms |
15552 KB |
Output is correct |
7 |
Correct |
33 ms |
15428 KB |
Output is correct |
8 |
Correct |
34 ms |
16248 KB |
Output is correct |
9 |
Correct |
41 ms |
16180 KB |
Output is correct |
10 |
Correct |
32 ms |
13632 KB |
Output is correct |
11 |
Correct |
27 ms |
13644 KB |
Output is correct |
12 |
Correct |
26 ms |
13448 KB |
Output is correct |
13 |
Correct |
31 ms |
13300 KB |
Output is correct |
14 |
Correct |
28 ms |
13500 KB |
Output is correct |
15 |
Correct |
28 ms |
14024 KB |
Output is correct |
16 |
Correct |
40 ms |
16156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
13176 KB |
Output is correct |
2 |
Correct |
0 ms |
784 KB |
Output is correct |
3 |
Correct |
22 ms |
12852 KB |
Output is correct |
4 |
Correct |
33 ms |
14676 KB |
Output is correct |
5 |
Correct |
45 ms |
14644 KB |
Output is correct |
6 |
Correct |
26 ms |
13180 KB |
Output is correct |
7 |
Correct |
26 ms |
13156 KB |
Output is correct |
8 |
Correct |
31 ms |
14152 KB |
Output is correct |
9 |
Correct |
31 ms |
13908 KB |
Output is correct |
10 |
Correct |
28 ms |
13700 KB |
Output is correct |
11 |
Correct |
33 ms |
13692 KB |
Output is correct |
12 |
Correct |
35 ms |
13760 KB |
Output is correct |
13 |
Correct |
30 ms |
13688 KB |
Output is correct |
14 |
Correct |
31 ms |
14216 KB |
Output is correct |
15 |
Correct |
31 ms |
13960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
13176 KB |
Output is correct |
2 |
Correct |
0 ms |
784 KB |
Output is correct |
3 |
Correct |
22 ms |
12852 KB |
Output is correct |
4 |
Correct |
33 ms |
14676 KB |
Output is correct |
5 |
Correct |
45 ms |
14644 KB |
Output is correct |
6 |
Correct |
26 ms |
13180 KB |
Output is correct |
7 |
Correct |
26 ms |
13156 KB |
Output is correct |
8 |
Correct |
31 ms |
14152 KB |
Output is correct |
9 |
Correct |
31 ms |
13908 KB |
Output is correct |
10 |
Correct |
28 ms |
13700 KB |
Output is correct |
11 |
Correct |
33 ms |
13692 KB |
Output is correct |
12 |
Correct |
35 ms |
13760 KB |
Output is correct |
13 |
Correct |
30 ms |
13688 KB |
Output is correct |
14 |
Correct |
31 ms |
14216 KB |
Output is correct |
15 |
Correct |
31 ms |
13960 KB |
Output is correct |
16 |
Correct |
23 ms |
11608 KB |
Output is correct |
17 |
Correct |
22 ms |
11600 KB |
Output is correct |
18 |
Correct |
26 ms |
11688 KB |
Output is correct |
19 |
Correct |
28 ms |
11600 KB |
Output is correct |
20 |
Correct |
27 ms |
12224 KB |
Output is correct |
21 |
Correct |
26 ms |
11944 KB |
Output is correct |
22 |
Correct |
31 ms |
14164 KB |
Output is correct |
23 |
Correct |
25 ms |
11964 KB |
Output is correct |
24 |
Correct |
25 ms |
11708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1048 KB |
Output is correct |
2 |
Correct |
0 ms |
784 KB |
Output is correct |
3 |
Correct |
0 ms |
1056 KB |
Output is correct |
4 |
Correct |
2 ms |
1048 KB |
Output is correct |
5 |
Correct |
2 ms |
1016 KB |
Output is correct |
6 |
Correct |
2 ms |
1040 KB |
Output is correct |
7 |
Correct |
2 ms |
1052 KB |
Output is correct |
8 |
Correct |
0 ms |
1048 KB |
Output is correct |
9 |
Correct |
0 ms |
1048 KB |
Output is correct |
10 |
Correct |
1 ms |
1056 KB |
Output is correct |
11 |
Correct |
1 ms |
1056 KB |
Output is correct |
12 |
Correct |
1 ms |
1048 KB |
Output is correct |
13 |
Correct |
0 ms |
1048 KB |
Output is correct |
14 |
Correct |
1 ms |
1056 KB |
Output is correct |
15 |
Correct |
0 ms |
1056 KB |
Output is correct |
16 |
Correct |
2 ms |
1052 KB |
Output is correct |
17 |
Correct |
1 ms |
1052 KB |
Output is correct |
18 |
Correct |
2 ms |
1040 KB |
Output is correct |
19 |
Correct |
2 ms |
1048 KB |
Output is correct |
20 |
Correct |
2 ms |
1040 KB |
Output is correct |
21 |
Correct |
0 ms |
1048 KB |
Output is correct |
22 |
Correct |
1 ms |
1048 KB |
Output is correct |
23 |
Correct |
1 ms |
1040 KB |
Output is correct |
24 |
Correct |
0 ms |
1052 KB |
Output is correct |
25 |
Correct |
2 ms |
1348 KB |
Output is correct |
26 |
Correct |
1 ms |
1052 KB |
Output is correct |
27 |
Correct |
1 ms |
1044 KB |
Output is correct |
28 |
Correct |
1 ms |
1056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
11388 KB |
Output is correct |
2 |
Correct |
26 ms |
11904 KB |
Output is correct |
3 |
Correct |
0 ms |
784 KB |
Output is correct |
4 |
Correct |
20 ms |
11312 KB |
Output is correct |
5 |
Correct |
32 ms |
12668 KB |
Output is correct |
6 |
Correct |
33 ms |
12680 KB |
Output is correct |
7 |
Correct |
26 ms |
11652 KB |
Output is correct |
8 |
Correct |
28 ms |
11616 KB |
Output is correct |
9 |
Correct |
32 ms |
12636 KB |
Output is correct |
10 |
Correct |
31 ms |
12592 KB |
Output is correct |
11 |
Correct |
34 ms |
12668 KB |
Output is correct |
12 |
Correct |
32 ms |
12712 KB |
Output is correct |
13 |
Correct |
30 ms |
12648 KB |
Output is correct |
14 |
Correct |
31 ms |
12668 KB |
Output is correct |
15 |
Correct |
31 ms |
12680 KB |
Output is correct |
16 |
Correct |
33 ms |
12616 KB |
Output is correct |
17 |
Correct |
31 ms |
12148 KB |
Output is correct |
18 |
Correct |
27 ms |
12400 KB |
Output is correct |
19 |
Correct |
28 ms |
12428 KB |
Output is correct |
20 |
Correct |
33 ms |
12396 KB |
Output is correct |
21 |
Correct |
30 ms |
12376 KB |
Output is correct |
22 |
Correct |
30 ms |
12412 KB |
Output is correct |
23 |
Correct |
26 ms |
11656 KB |
Output is correct |
24 |
Correct |
25 ms |
11452 KB |
Output is correct |
25 |
Correct |
25 ms |
11656 KB |
Output is correct |
26 |
Correct |
25 ms |
11652 KB |
Output is correct |
27 |
Correct |
26 ms |
11896 KB |
Output is correct |
28 |
Correct |
27 ms |
11868 KB |
Output is correct |
29 |
Correct |
33 ms |
11848 KB |
Output is correct |
30 |
Correct |
26 ms |
12112 KB |
Output is correct |
31 |
Correct |
27 ms |
11392 KB |
Output is correct |
32 |
Correct |
24 ms |
11388 KB |
Output is correct |
33 |
Correct |
25 ms |
11384 KB |
Output is correct |
34 |
Correct |
25 ms |
11648 KB |
Output is correct |
35 |
Correct |
27 ms |
12204 KB |
Output is correct |
36 |
Correct |
28 ms |
12016 KB |
Output is correct |
37 |
Correct |
27 ms |
11940 KB |
Output is correct |
38 |
Correct |
30 ms |
12072 KB |
Output is correct |
39 |
Correct |
30 ms |
11868 KB |
Output is correct |
40 |
Correct |
28 ms |
11900 KB |
Output is correct |
41 |
Correct |
28 ms |
12152 KB |
Output is correct |
42 |
Correct |
28 ms |
12172 KB |
Output is correct |
43 |
Correct |
28 ms |
12140 KB |
Output is correct |
44 |
Correct |
30 ms |
12224 KB |
Output is correct |
45 |
Correct |
30 ms |
12164 KB |
Output is correct |
46 |
Correct |
31 ms |
12160 KB |
Output is correct |
47 |
Correct |
26 ms |
11736 KB |
Output is correct |
48 |
Correct |
26 ms |
11900 KB |
Output is correct |
49 |
Correct |
27 ms |
11648 KB |
Output is correct |
50 |
Correct |
34 ms |
11804 KB |
Output is correct |
51 |
Correct |
28 ms |
11592 KB |
Output is correct |
52 |
Correct |
25 ms |
11648 KB |
Output is correct |
53 |
Correct |
25 ms |
11640 KB |
Output is correct |
54 |
Correct |
25 ms |
11660 KB |
Output is correct |
55 |
Correct |
28 ms |
11768 KB |
Output is correct |
56 |
Correct |
28 ms |
11628 KB |
Output is correct |
57 |
Correct |
26 ms |
11652 KB |
Output is correct |
58 |
Correct |
24 ms |
11656 KB |
Output is correct |
59 |
Correct |
25 ms |
11628 KB |
Output is correct |
60 |
Correct |
24 ms |
11700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
11364 KB |
Output is correct |
2 |
Correct |
26 ms |
11544 KB |
Output is correct |
3 |
Correct |
0 ms |
796 KB |
Output is correct |
4 |
Correct |
20 ms |
11328 KB |
Output is correct |
5 |
Correct |
33 ms |
12596 KB |
Output is correct |
6 |
Correct |
30 ms |
12644 KB |
Output is correct |
7 |
Correct |
27 ms |
11576 KB |
Output is correct |
8 |
Correct |
25 ms |
11620 KB |
Output is correct |
9 |
Correct |
31 ms |
12624 KB |
Output is correct |
10 |
Correct |
31 ms |
12604 KB |
Output is correct |
11 |
Correct |
31 ms |
12796 KB |
Output is correct |
12 |
Correct |
30 ms |
12580 KB |
Output is correct |
13 |
Correct |
37 ms |
12600 KB |
Output is correct |
14 |
Correct |
32 ms |
12648 KB |
Output is correct |
15 |
Correct |
31 ms |
12660 KB |
Output is correct |
16 |
Correct |
32 ms |
12576 KB |
Output is correct |
17 |
Correct |
28 ms |
12264 KB |
Output is correct |
18 |
Correct |
28 ms |
12388 KB |
Output is correct |
19 |
Correct |
28 ms |
12416 KB |
Output is correct |
20 |
Correct |
27 ms |
12168 KB |
Output is correct |
21 |
Correct |
30 ms |
12424 KB |
Output is correct |
22 |
Correct |
28 ms |
12376 KB |
Output is correct |
23 |
Correct |
34 ms |
11332 KB |
Output is correct |
24 |
Correct |
26 ms |
11392 KB |
Output is correct |
25 |
Correct |
25 ms |
11636 KB |
Output is correct |
26 |
Correct |
26 ms |
11676 KB |
Output is correct |
27 |
Correct |
27 ms |
11928 KB |
Output is correct |
28 |
Correct |
27 ms |
11924 KB |
Output is correct |
29 |
Correct |
28 ms |
11808 KB |
Output is correct |
30 |
Correct |
26 ms |
11880 KB |
Output is correct |
31 |
Correct |
24 ms |
11456 KB |
Output is correct |
32 |
Correct |
24 ms |
11400 KB |
Output is correct |
33 |
Correct |
25 ms |
11648 KB |
Output is correct |
34 |
Correct |
25 ms |
11648 KB |
Output is correct |
35 |
Correct |
27 ms |
11908 KB |
Output is correct |
36 |
Correct |
30 ms |
11952 KB |
Output is correct |
37 |
Correct |
26 ms |
11904 KB |
Output is correct |
38 |
Correct |
30 ms |
11828 KB |
Output is correct |
39 |
Correct |
30 ms |
11776 KB |
Output is correct |
40 |
Correct |
26 ms |
11908 KB |
Output is correct |
41 |
Correct |
28 ms |
12360 KB |
Output is correct |
42 |
Correct |
30 ms |
12068 KB |
Output is correct |
43 |
Correct |
28 ms |
12152 KB |
Output is correct |
44 |
Correct |
28 ms |
12172 KB |
Output is correct |
45 |
Correct |
37 ms |
12300 KB |
Output is correct |
46 |
Correct |
28 ms |
12164 KB |
Output is correct |
47 |
Correct |
27 ms |
11884 KB |
Output is correct |
48 |
Correct |
26 ms |
11844 KB |
Output is correct |
49 |
Correct |
27 ms |
11660 KB |
Output is correct |
50 |
Correct |
27 ms |
11888 KB |
Output is correct |
51 |
Correct |
30 ms |
11612 KB |
Output is correct |
52 |
Correct |
27 ms |
11960 KB |
Output is correct |
53 |
Correct |
24 ms |
11656 KB |
Output is correct |
54 |
Correct |
30 ms |
11636 KB |
Output is correct |
55 |
Correct |
24 ms |
11644 KB |
Output is correct |
56 |
Correct |
24 ms |
11648 KB |
Output is correct |
57 |
Correct |
32 ms |
11660 KB |
Output is correct |
58 |
Correct |
25 ms |
11692 KB |
Output is correct |
59 |
Correct |
24 ms |
11568 KB |
Output is correct |
60 |
Correct |
28 ms |
11600 KB |
Output is correct |