#include <bits/stdc++.h>
#include "Anthony.h"
using namespace std;
namespace {
} // namespace
std::vector<int> Mark(int N, int M, int A, int B, std::vector<int> U, std::vector<int> V) {
vector<int> rt (M, 0);
vector<vector<int>> G (N);
for (int i = 0; i < M; i++) {
G[U[i]].push_back(V[i]);
G[V[i]].push_back(U[i]);
}
if (A >= 3) {
vector<int> dep (N, -1);
queue<int> Q;
Q.push(0);
dep[0] = 0;
while (!Q.empty()) {
int p = Q.front();
Q.pop();
for (auto e : G[p]) {
if (dep[e] == -1) {
dep[e] = dep[p] + 1;
Q.push(e);
}
}
}
for (int i = 0; i < M; i++) {
int x = U[i], y = V[i];
if (dep[x] > dep[y]) {
swap(x, y);
}
rt[i] = dep[x] % 3;
}
} else {
vector<int> col (N, 0);
vector<int> dep (N, 0);
function<void(int, int, int)> dfs = [&] (int p, int fa, int cdis) {
static char str[] = "110100";
if (p) {
cdis = (G[fa].size() == 2u) ? (cdis % 6 + 1) : (0);
col[p] = (!cdis) ? (col[fa] ^ 1) : (str[cdis - 1] - '0');
dep[p] = dep[fa] + 1;
}
for (auto e : G[p]) {
if (e ^ fa) {
dfs(e, p, cdis);
}
}
};
dfs(0, -1, 0);
for (int i = 0; i < M; i++) {
int x = U[i], y = V[i];
if (dep[x] > dep[y]) {
swap(x, y);
}
rt[i] = col[y];
// cerr << x << " " << y << " " << rt[i] << '\n';
}
}
return rt;
}
#include <bits/stdc++.h>
#include "Catherine.h"
using namespace std;
namespace {
int A, B;
bool has_dir;
int last_col;
vector<int> seq;
bool match(const char* s) {
int len = strlen(s);
if (len > seq.size()) {
return false;
}
int t = seq.size();
while (len-- && t--) {
if (s[len] - '0' != seq[t]) {
return false;
}
}
return true;
}
} // namespace
void Init(int A, int B) {
::A = A;
::B = B;
has_dir = false;
last_col = -1;
}
int Move(std::vector<int> y) {
if (A >= 3) {
const static int go[3] = {1, 2, 0};
vector<int> id;
for (int i = 0; i < A; i++) {
if (y[i]) {
id.push_back(i);
}
}
int sz = id.size();
assert(sz <= 2 && sz >= 1);
if (sz == 1) {
return id[0];
} else {
return go[3 ^ id[0] ^ id[1]];
}
} else {
if (has_dir) {
if (!y[0] + !y[1] == 1) {
return last_col = !y[0];
} else {
return last_col = last_col ^ 1;
}
} else {
int sum = last_col != -1;
for (auto x : y) {
sum += x;
}
if (sum > 2) {
has_dir = true;
if (last_col == -1) {
return last_col = y[0] > y[1];
} else {
if (!y[last_col]) {
return -1;
} else {
return last_col = last_col ^ 1;
}
}
} else if (sum == 1) {
has_dir = true;
if (last_col == -1) {
return last_col = !y[0];
} else {
return -1;
}
} else {
if (last_col == -1) {
if (y[0] == 2) {
last_col = 0;
seq = vector<int>{0, 0};
} else if (y[1] == 2) {
last_col = 1;
seq = vector<int>{1, 1};
} else {
last_col = 1;
seq = vector<int>{0, 1};
}
return last_col;
} else {
seq.push_back(!y[0]);
int sz = seq.size();
if (sz >= 4) {
if (seq[sz - 2] == 1 && seq[sz - 3] == 0 && seq[sz - 4] == 1) {
has_dir = true;
if (seq[sz - 1] == 0) {
return -1;
}
} else if (seq[sz - 1] == 1 && seq[sz - 2] == 0 && seq[sz - 3] == 1) {
has_dir = true;
if (seq[sz - 4] == 1) {
return -1;
}
} else if (match("00110") || match("01001")) {
has_dir = true;
return -1;
}
}
return last_col = !y[0];
}
}
}
}
return -1;
}
Compilation message
Catherine.cpp: In function 'bool {anonymous}::match(const char*)':
Catherine.cpp:15:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (len > seq.size()) {
~~~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
63 ms |
15096 KB |
Output is correct |
2 |
Correct |
10 ms |
900 KB |
Output is correct |
3 |
Correct |
56 ms |
14568 KB |
Output is correct |
4 |
Correct |
78 ms |
16388 KB |
Output is correct |
5 |
Correct |
83 ms |
16400 KB |
Output is correct |
6 |
Correct |
57 ms |
15196 KB |
Output is correct |
7 |
Correct |
68 ms |
15288 KB |
Output is correct |
8 |
Correct |
75 ms |
16020 KB |
Output is correct |
9 |
Correct |
75 ms |
15952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
63 ms |
15096 KB |
Output is correct |
2 |
Correct |
10 ms |
900 KB |
Output is correct |
3 |
Correct |
56 ms |
14568 KB |
Output is correct |
4 |
Correct |
78 ms |
16388 KB |
Output is correct |
5 |
Correct |
83 ms |
16400 KB |
Output is correct |
6 |
Correct |
57 ms |
15196 KB |
Output is correct |
7 |
Correct |
68 ms |
15288 KB |
Output is correct |
8 |
Correct |
75 ms |
16020 KB |
Output is correct |
9 |
Correct |
75 ms |
15952 KB |
Output is correct |
10 |
Correct |
54 ms |
13244 KB |
Output is correct |
11 |
Correct |
55 ms |
13284 KB |
Output is correct |
12 |
Correct |
57 ms |
13172 KB |
Output is correct |
13 |
Correct |
52 ms |
13276 KB |
Output is correct |
14 |
Correct |
58 ms |
13324 KB |
Output is correct |
15 |
Correct |
74 ms |
13660 KB |
Output is correct |
16 |
Correct |
78 ms |
16116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
57 ms |
12796 KB |
Output is correct |
2 |
Correct |
9 ms |
780 KB |
Output is correct |
3 |
Correct |
66 ms |
12404 KB |
Output is correct |
4 |
Correct |
71 ms |
14196 KB |
Output is correct |
5 |
Correct |
88 ms |
14200 KB |
Output is correct |
6 |
Correct |
61 ms |
12984 KB |
Output is correct |
7 |
Correct |
64 ms |
13172 KB |
Output is correct |
8 |
Correct |
73 ms |
13752 KB |
Output is correct |
9 |
Correct |
76 ms |
13788 KB |
Output is correct |
10 |
Correct |
64 ms |
13544 KB |
Output is correct |
11 |
Correct |
63 ms |
13520 KB |
Output is correct |
12 |
Correct |
63 ms |
13416 KB |
Output is correct |
13 |
Correct |
64 ms |
13520 KB |
Output is correct |
14 |
Correct |
68 ms |
13908 KB |
Output is correct |
15 |
Correct |
74 ms |
13672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
57 ms |
12796 KB |
Output is correct |
2 |
Correct |
9 ms |
780 KB |
Output is correct |
3 |
Correct |
66 ms |
12404 KB |
Output is correct |
4 |
Correct |
71 ms |
14196 KB |
Output is correct |
5 |
Correct |
88 ms |
14200 KB |
Output is correct |
6 |
Correct |
61 ms |
12984 KB |
Output is correct |
7 |
Correct |
64 ms |
13172 KB |
Output is correct |
8 |
Correct |
73 ms |
13752 KB |
Output is correct |
9 |
Correct |
76 ms |
13788 KB |
Output is correct |
10 |
Correct |
64 ms |
13544 KB |
Output is correct |
11 |
Correct |
63 ms |
13520 KB |
Output is correct |
12 |
Correct |
63 ms |
13416 KB |
Output is correct |
13 |
Correct |
64 ms |
13520 KB |
Output is correct |
14 |
Correct |
68 ms |
13908 KB |
Output is correct |
15 |
Correct |
74 ms |
13672 KB |
Output is correct |
16 |
Correct |
50 ms |
11448 KB |
Output is correct |
17 |
Correct |
63 ms |
11356 KB |
Output is correct |
18 |
Correct |
59 ms |
11364 KB |
Output is correct |
19 |
Correct |
64 ms |
11460 KB |
Output is correct |
20 |
Correct |
64 ms |
11984 KB |
Output is correct |
21 |
Correct |
55 ms |
11620 KB |
Output is correct |
22 |
Correct |
67 ms |
13988 KB |
Output is correct |
23 |
Correct |
57 ms |
11364 KB |
Output is correct |
24 |
Correct |
64 ms |
11356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
1100 KB |
Output is correct |
2 |
Correct |
10 ms |
908 KB |
Output is correct |
3 |
Correct |
10 ms |
1128 KB |
Output is correct |
4 |
Correct |
11 ms |
1036 KB |
Output is correct |
5 |
Correct |
10 ms |
1044 KB |
Output is correct |
6 |
Correct |
10 ms |
1036 KB |
Output is correct |
7 |
Correct |
10 ms |
1084 KB |
Output is correct |
8 |
Correct |
10 ms |
1040 KB |
Output is correct |
9 |
Correct |
10 ms |
1024 KB |
Output is correct |
10 |
Correct |
12 ms |
1128 KB |
Output is correct |
11 |
Correct |
10 ms |
1048 KB |
Output is correct |
12 |
Correct |
11 ms |
1080 KB |
Output is correct |
13 |
Correct |
10 ms |
1084 KB |
Output is correct |
14 |
Correct |
10 ms |
1096 KB |
Output is correct |
15 |
Correct |
12 ms |
1176 KB |
Output is correct |
16 |
Correct |
11 ms |
1096 KB |
Output is correct |
17 |
Correct |
10 ms |
1060 KB |
Output is correct |
18 |
Correct |
11 ms |
1128 KB |
Output is correct |
19 |
Correct |
11 ms |
1104 KB |
Output is correct |
20 |
Correct |
13 ms |
1040 KB |
Output is correct |
21 |
Correct |
10 ms |
1168 KB |
Output is correct |
22 |
Correct |
11 ms |
1168 KB |
Output is correct |
23 |
Correct |
10 ms |
1228 KB |
Output is correct |
24 |
Correct |
11 ms |
1176 KB |
Output is correct |
25 |
Correct |
10 ms |
1040 KB |
Output is correct |
26 |
Correct |
11 ms |
1048 KB |
Output is correct |
27 |
Correct |
10 ms |
1048 KB |
Output is correct |
28 |
Correct |
11 ms |
1040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
10928 KB |
Output is correct |
2 |
Correct |
60 ms |
12436 KB |
Output is correct |
3 |
Correct |
9 ms |
792 KB |
Output is correct |
4 |
Correct |
55 ms |
10824 KB |
Output is correct |
5 |
Correct |
70 ms |
14068 KB |
Output is correct |
6 |
Correct |
68 ms |
14132 KB |
Output is correct |
7 |
Correct |
68 ms |
13232 KB |
Output is correct |
8 |
Correct |
57 ms |
13504 KB |
Output is correct |
9 |
Correct |
68 ms |
14312 KB |
Output is correct |
10 |
Correct |
65 ms |
14432 KB |
Output is correct |
11 |
Correct |
80 ms |
14440 KB |
Output is correct |
12 |
Correct |
72 ms |
14448 KB |
Output is correct |
13 |
Correct |
66 ms |
14376 KB |
Output is correct |
14 |
Correct |
88 ms |
14264 KB |
Output is correct |
15 |
Correct |
88 ms |
14312 KB |
Output is correct |
16 |
Correct |
68 ms |
14304 KB |
Output is correct |
17 |
Correct |
75 ms |
14056 KB |
Output is correct |
18 |
Correct |
67 ms |
13928 KB |
Output is correct |
19 |
Correct |
62 ms |
14048 KB |
Output is correct |
20 |
Correct |
72 ms |
14056 KB |
Output is correct |
21 |
Correct |
66 ms |
13928 KB |
Output is correct |
22 |
Correct |
71 ms |
14024 KB |
Output is correct |
23 |
Correct |
56 ms |
11240 KB |
Output is correct |
24 |
Correct |
63 ms |
11216 KB |
Output is correct |
25 |
Correct |
55 ms |
11752 KB |
Output is correct |
26 |
Correct |
57 ms |
11872 KB |
Output is correct |
27 |
Correct |
59 ms |
12640 KB |
Output is correct |
28 |
Correct |
64 ms |
12776 KB |
Output is correct |
29 |
Correct |
65 ms |
12780 KB |
Output is correct |
30 |
Correct |
78 ms |
12776 KB |
Output is correct |
31 |
Correct |
60 ms |
11240 KB |
Output is correct |
32 |
Correct |
50 ms |
11112 KB |
Output is correct |
33 |
Correct |
53 ms |
11624 KB |
Output is correct |
34 |
Correct |
77 ms |
11880 KB |
Output is correct |
35 |
Correct |
67 ms |
12508 KB |
Output is correct |
36 |
Correct |
63 ms |
12528 KB |
Output is correct |
37 |
Correct |
68 ms |
12520 KB |
Output is correct |
38 |
Correct |
66 ms |
12528 KB |
Output is correct |
39 |
Correct |
65 ms |
12516 KB |
Output is correct |
40 |
Correct |
60 ms |
12536 KB |
Output is correct |
41 |
Correct |
64 ms |
13348 KB |
Output is correct |
42 |
Correct |
80 ms |
13252 KB |
Output is correct |
43 |
Correct |
87 ms |
13288 KB |
Output is correct |
44 |
Correct |
74 ms |
13396 KB |
Output is correct |
45 |
Correct |
69 ms |
13288 KB |
Output is correct |
46 |
Correct |
66 ms |
13520 KB |
Output is correct |
47 |
Correct |
60 ms |
12384 KB |
Output is correct |
48 |
Correct |
62 ms |
12264 KB |
Output is correct |
49 |
Correct |
59 ms |
12204 KB |
Output is correct |
50 |
Correct |
68 ms |
12284 KB |
Output is correct |
51 |
Correct |
61 ms |
11524 KB |
Output is correct |
52 |
Correct |
60 ms |
11488 KB |
Output is correct |
53 |
Correct |
52 ms |
11632 KB |
Output is correct |
54 |
Correct |
51 ms |
11520 KB |
Output is correct |
55 |
Correct |
51 ms |
11756 KB |
Output is correct |
56 |
Correct |
64 ms |
11584 KB |
Output is correct |
57 |
Correct |
52 ms |
11240 KB |
Output is correct |
58 |
Correct |
55 ms |
11248 KB |
Output is correct |
59 |
Correct |
65 ms |
11504 KB |
Output is correct |
60 |
Correct |
64 ms |
11360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
11004 KB |
Output is correct |
2 |
Correct |
53 ms |
12276 KB |
Output is correct |
3 |
Correct |
9 ms |
1016 KB |
Output is correct |
4 |
Correct |
51 ms |
10940 KB |
Output is correct |
5 |
Correct |
64 ms |
14076 KB |
Output is correct |
6 |
Correct |
63 ms |
14220 KB |
Output is correct |
7 |
Correct |
60 ms |
13268 KB |
Output is correct |
8 |
Correct |
64 ms |
13416 KB |
Output is correct |
9 |
Correct |
80 ms |
14340 KB |
Output is correct |
10 |
Correct |
71 ms |
14380 KB |
Output is correct |
11 |
Correct |
77 ms |
14356 KB |
Output is correct |
12 |
Correct |
67 ms |
14384 KB |
Output is correct |
13 |
Correct |
80 ms |
14452 KB |
Output is correct |
14 |
Correct |
73 ms |
14296 KB |
Output is correct |
15 |
Correct |
78 ms |
14300 KB |
Output is correct |
16 |
Correct |
73 ms |
14312 KB |
Output is correct |
17 |
Correct |
65 ms |
14064 KB |
Output is correct |
18 |
Correct |
62 ms |
14064 KB |
Output is correct |
19 |
Correct |
64 ms |
14088 KB |
Output is correct |
20 |
Correct |
80 ms |
14152 KB |
Output is correct |
21 |
Correct |
73 ms |
14100 KB |
Output is correct |
22 |
Correct |
73 ms |
13928 KB |
Output is correct |
23 |
Correct |
59 ms |
11232 KB |
Output is correct |
24 |
Correct |
51 ms |
11240 KB |
Output is correct |
25 |
Correct |
63 ms |
11752 KB |
Output is correct |
26 |
Correct |
52 ms |
11868 KB |
Output is correct |
27 |
Correct |
55 ms |
12648 KB |
Output is correct |
28 |
Correct |
67 ms |
12640 KB |
Output is correct |
29 |
Correct |
62 ms |
12756 KB |
Output is correct |
30 |
Correct |
67 ms |
12768 KB |
Output is correct |
31 |
Correct |
49 ms |
11340 KB |
Output is correct |
32 |
Correct |
55 ms |
11136 KB |
Output is correct |
33 |
Correct |
64 ms |
11840 KB |
Output is correct |
34 |
Correct |
62 ms |
11880 KB |
Output is correct |
35 |
Correct |
59 ms |
12656 KB |
Output is correct |
36 |
Correct |
62 ms |
12520 KB |
Output is correct |
37 |
Correct |
56 ms |
12568 KB |
Output is correct |
38 |
Correct |
84 ms |
12512 KB |
Output is correct |
39 |
Correct |
68 ms |
12512 KB |
Output is correct |
40 |
Correct |
79 ms |
12520 KB |
Output is correct |
41 |
Correct |
80 ms |
13356 KB |
Output is correct |
42 |
Correct |
92 ms |
13352 KB |
Output is correct |
43 |
Correct |
66 ms |
13364 KB |
Output is correct |
44 |
Correct |
68 ms |
13280 KB |
Output is correct |
45 |
Correct |
70 ms |
13288 KB |
Output is correct |
46 |
Correct |
78 ms |
13348 KB |
Output is correct |
47 |
Correct |
74 ms |
12344 KB |
Output is correct |
48 |
Correct |
67 ms |
12432 KB |
Output is correct |
49 |
Correct |
64 ms |
12292 KB |
Output is correct |
50 |
Correct |
66 ms |
12456 KB |
Output is correct |
51 |
Correct |
56 ms |
11500 KB |
Output is correct |
52 |
Correct |
51 ms |
11384 KB |
Output is correct |
53 |
Correct |
54 ms |
11632 KB |
Output is correct |
54 |
Correct |
69 ms |
11520 KB |
Output is correct |
55 |
Correct |
56 ms |
11624 KB |
Output is correct |
56 |
Correct |
53 ms |
11496 KB |
Output is correct |
57 |
Correct |
73 ms |
11248 KB |
Output is correct |
58 |
Correct |
56 ms |
11240 KB |
Output is correct |
59 |
Correct |
64 ms |
11480 KB |
Output is correct |
60 |
Correct |
62 ms |
11504 KB |
Output is correct |