#include "Anthony.h"
#include <bits/stdc++.h>
using namespace std;
const int nmax = 2e4 + 5;
using pii = pair<int,int>;
vector<int> rez;
//001011 101100
namespace {
#define F nustiusacompilezcodurilol
const string F = "001011001011";
vector<pii> g[nmax];
int p[nmax];
void dfs(int node, int f = 0, int state = -1) {
if(g[node].size() - (node != f) == 1) {
if(state == -1) {
if(p[node] == 0)
state = 1;
else
state = 3;
}
else
state = (state + 1) % 12;
}
else
state = -1;
for(int i = 0; i < g[node].size(); i++) {
int x, e;
tie(e, x) = g[node][i];
if(x == f)
swap(g[node][i], g[node].back()),
g[node].pop_back(),
i--;
else {
if(state == -1)
rez[e] = p[node] ^ 1;
else
rez[e] = F[state] - '0';
p[x] = rez[e];
dfs(x, node, state);
}
}
return;
}
} // namespace
std::vector<int> Mark(int N, int M, int A, int B,
std::vector<int> U, std::vector<int> V) {
rez.resize(M, -1);
for (int i = 0; i < M; ++i) {
g[U[i]].emplace_back(i, V[i]);
g[V[i]].emplace_back(i, U[i]);
}
if(A > 2) {
queue<int> que;
vector<int> occ(N, 0);
que.push(0);
occ[0] = 3;
while(!que.empty()) {
int node = que.front(), mine = occ[node] - 1;
//cerr << node << ' ' << occ[node] << '\n';
que.pop();
for(auto [e, x] : g[node]) {
rez[e] = rez[e] == -1? (mine + 1) % 3 : rez[e];
if(occ[x] == 0) {
occ[x] = rez[e] + 1;
que.push(x);
}
}
}
//for(int i = 0; i < M; i++) {
//cerr << rez[i] << ' ' << U[i] << ' ' << V[i] << '\n';
//}
}
else {
dfs(0);
for(int i = 0; i < M; i++) {
cerr << rez[i] << ' ' << U[i] << ' ' << V[i] << '\n';
}
}
return rez;
}
#undef F
#include "Catherine.h"
#include <bits/stdc++.h>
using namespace std;
namespace {
const string F = "001011001011";
int A, B;
int variable_example = 0;
unordered_set<string> goodstrings;
void initgs() {
string s = F + F;
reverse(s.begin(), s.end());
int n = F.size();
for(int i = 0; i < n; i++) {
goodstrings.insert(s.substr(i, 5));
}
return;
}
int timer, lastval = -1;
int state = 0;
string curr = "";
int gsum(vector<int> v) { return accumulate(v.begin(), v.end(), 0); }
}
int amogii = -1;
// 0 - 1 - 1 - 0 - 0 - 1 - 0 - 1 - 1 - 0 - 0 - 1 - 0 - 1 - 1 - 0 - 0 - 1 -
void Init(int A, int B) {
::A = min(3, A);
::B = B;
initgs();
}
int Move(std::vector<int> v) {
int sum = gsum(v);
if(A == 2) {
if(state == -1) {
if(sum == 0)
return -1; // ???
else if(lastval == -1 || sum == 1) {
if(v[0] > 0) return lastval = 0;
return lastval = 1;
}
else
return lastval ^= 1;
}
if(state == 0) {
if(sum == 1) {
int ptr = 0;
for(int i = 0; i < A; i++)
if(v[i] != 0) {
lastval = i;
break;
}
state = -1;
return lastval;
}
if(sum == 2) {
state = 1;
if(v[1] == 0) {
curr = "00";
return lastval = 0;
}
if(v[1] == 1) {
curr = "01";
return lastval = 1;
}
curr = "11";
return lastval = 1;
}
else {
for(int i = 0; i < A; i++)
if(v[i] == 1) {
lastval = i;
break;
}
state = -1;
return lastval;
}
}
if(state <= 3) {
if(sum == 0) {
state = -1;
return -1;
}
if(sum > 1) {
state = -1;
if(v[lastval] == 0) {
return -1;
}
return lastval ^= 1;
}
else {
if(v[0] == 1) curr += '0';
else curr += '1';
if(state == 3) {
state = -1;
if(goodstrings.count(curr))
return lastval = curr.back() - '0';
return -1;
}
else {
state++;
return lastval = curr.back() - '0';
}
}
}
return -1;
}
else {
int cnt = 0;
for(auto x : v)
if(x != 0)
cnt++;
if(cnt == 0)
return -1;
else if(cnt == 1) {
if(v[0] != 0) return 0;
if(v[1] != 0) return 1;
if(v[2] != 0) return 2;
//for(auto x : v)
//cerr << x << ' ';
//cerr << '\n';
}
else { // X --0-- Y --1-- Z --2-- T --0-- U
if(v[0] == 0) return 1;
if(v[1] == 0) return 2;
if(v[2] == 0) return 0;
}
while(1);
}
}
Compilation message
Anthony.cpp: In function 'void {anonymous}::dfs(int, int, int)':
Anthony.cpp:30:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | for(int i = 0; i < g[node].size(); i++) {
| ~~^~~~~~~~~~~~~~~~
Anthony.cpp: In function 'std::vector<int> Mark(int, int, int, int, std::vector<int>, std::vector<int>)':
Anthony.cpp:66:16: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
66 | for(auto [e, x] : g[node]) {
| ^
Catherine.cpp: In function 'int Move(std::vector<int>)':
Catherine.cpp:50:13: warning: unused variable 'ptr' [-Wunused-variable]
50 | int ptr = 0;
| ^~~
Catherine.cpp: At global scope:
Catherine.cpp:20:7: warning: '{anonymous}::timer' defined but not used [-Wunused-variable]
20 | int timer, lastval = -1;
| ^~~~~
Catherine.cpp:9:7: warning: '{anonymous}::variable_example' defined but not used [-Wunused-variable]
9 | int variable_example = 0;
| ^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
15464 KB |
Output is correct |
2 |
Correct |
0 ms |
1032 KB |
Output is correct |
3 |
Correct |
31 ms |
14808 KB |
Output is correct |
4 |
Correct |
56 ms |
16420 KB |
Output is correct |
5 |
Correct |
44 ms |
16444 KB |
Output is correct |
6 |
Correct |
39 ms |
15208 KB |
Output is correct |
7 |
Correct |
34 ms |
15284 KB |
Output is correct |
8 |
Correct |
45 ms |
16072 KB |
Output is correct |
9 |
Correct |
45 ms |
15916 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
15464 KB |
Output is correct |
2 |
Correct |
0 ms |
1032 KB |
Output is correct |
3 |
Correct |
31 ms |
14808 KB |
Output is correct |
4 |
Correct |
56 ms |
16420 KB |
Output is correct |
5 |
Correct |
44 ms |
16444 KB |
Output is correct |
6 |
Correct |
39 ms |
15208 KB |
Output is correct |
7 |
Correct |
34 ms |
15284 KB |
Output is correct |
8 |
Correct |
45 ms |
16072 KB |
Output is correct |
9 |
Correct |
45 ms |
15916 KB |
Output is correct |
10 |
Correct |
32 ms |
13280 KB |
Output is correct |
11 |
Correct |
31 ms |
13444 KB |
Output is correct |
12 |
Correct |
32 ms |
13444 KB |
Output is correct |
13 |
Correct |
31 ms |
13508 KB |
Output is correct |
14 |
Correct |
32 ms |
13688 KB |
Output is correct |
15 |
Correct |
39 ms |
14048 KB |
Output is correct |
16 |
Correct |
43 ms |
15976 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
13016 KB |
Output is correct |
2 |
Correct |
1 ms |
1032 KB |
Output is correct |
3 |
Correct |
27 ms |
12604 KB |
Output is correct |
4 |
Correct |
43 ms |
14308 KB |
Output is correct |
5 |
Correct |
44 ms |
14304 KB |
Output is correct |
6 |
Correct |
43 ms |
12964 KB |
Output is correct |
7 |
Correct |
32 ms |
13008 KB |
Output is correct |
8 |
Correct |
38 ms |
13624 KB |
Output is correct |
9 |
Correct |
39 ms |
13696 KB |
Output is correct |
10 |
Correct |
38 ms |
13424 KB |
Output is correct |
11 |
Correct |
38 ms |
13468 KB |
Output is correct |
12 |
Correct |
40 ms |
13412 KB |
Output is correct |
13 |
Correct |
38 ms |
13384 KB |
Output is correct |
14 |
Correct |
40 ms |
13672 KB |
Output is correct |
15 |
Correct |
44 ms |
13716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
13016 KB |
Output is correct |
2 |
Correct |
1 ms |
1032 KB |
Output is correct |
3 |
Correct |
27 ms |
12604 KB |
Output is correct |
4 |
Correct |
43 ms |
14308 KB |
Output is correct |
5 |
Correct |
44 ms |
14304 KB |
Output is correct |
6 |
Correct |
43 ms |
12964 KB |
Output is correct |
7 |
Correct |
32 ms |
13008 KB |
Output is correct |
8 |
Correct |
38 ms |
13624 KB |
Output is correct |
9 |
Correct |
39 ms |
13696 KB |
Output is correct |
10 |
Correct |
38 ms |
13424 KB |
Output is correct |
11 |
Correct |
38 ms |
13468 KB |
Output is correct |
12 |
Correct |
40 ms |
13412 KB |
Output is correct |
13 |
Correct |
38 ms |
13384 KB |
Output is correct |
14 |
Correct |
40 ms |
13672 KB |
Output is correct |
15 |
Correct |
44 ms |
13716 KB |
Output is correct |
16 |
Correct |
34 ms |
11568 KB |
Output is correct |
17 |
Correct |
30 ms |
11596 KB |
Output is correct |
18 |
Correct |
31 ms |
11448 KB |
Output is correct |
19 |
Correct |
34 ms |
11544 KB |
Output is correct |
20 |
Correct |
35 ms |
12204 KB |
Output is correct |
21 |
Correct |
39 ms |
11852 KB |
Output is correct |
22 |
Correct |
49 ms |
13756 KB |
Output is correct |
23 |
Correct |
33 ms |
11556 KB |
Output is correct |
24 |
Correct |
31 ms |
11632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
1376 KB |
Output is correct |
2 |
Correct |
1 ms |
1104 KB |
Output is correct |
3 |
Correct |
7 ms |
1280 KB |
Output is correct |
4 |
Correct |
5 ms |
1284 KB |
Output is correct |
5 |
Correct |
5 ms |
1356 KB |
Output is correct |
6 |
Correct |
6 ms |
1408 KB |
Output is correct |
7 |
Correct |
6 ms |
1344 KB |
Output is correct |
8 |
Correct |
8 ms |
1380 KB |
Output is correct |
9 |
Correct |
5 ms |
1424 KB |
Output is correct |
10 |
Correct |
6 ms |
1464 KB |
Output is correct |
11 |
Correct |
5 ms |
1404 KB |
Output is correct |
12 |
Correct |
5 ms |
1348 KB |
Output is correct |
13 |
Correct |
5 ms |
1296 KB |
Output is correct |
14 |
Correct |
5 ms |
1352 KB |
Output is correct |
15 |
Correct |
5 ms |
1336 KB |
Output is correct |
16 |
Correct |
5 ms |
1288 KB |
Output is correct |
17 |
Correct |
5 ms |
1284 KB |
Output is correct |
18 |
Correct |
6 ms |
1344 KB |
Output is correct |
19 |
Correct |
5 ms |
1288 KB |
Output is correct |
20 |
Correct |
5 ms |
1328 KB |
Output is correct |
21 |
Correct |
6 ms |
1288 KB |
Output is correct |
22 |
Correct |
5 ms |
1288 KB |
Output is correct |
23 |
Correct |
7 ms |
1356 KB |
Output is correct |
24 |
Correct |
5 ms |
1296 KB |
Output is correct |
25 |
Correct |
5 ms |
1348 KB |
Output is correct |
26 |
Correct |
6 ms |
1268 KB |
Output is correct |
27 |
Correct |
5 ms |
1352 KB |
Output is correct |
28 |
Correct |
6 ms |
1352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
164 ms |
11420 KB |
Output is correct |
2 |
Correct |
169 ms |
12920 KB |
Output is correct |
3 |
Correct |
1 ms |
1036 KB |
Output is correct |
4 |
Correct |
163 ms |
11584 KB |
Output is correct |
5 |
Correct |
181 ms |
14200 KB |
Output is correct |
6 |
Correct |
181 ms |
14232 KB |
Output is correct |
7 |
Correct |
183 ms |
13344 KB |
Output is correct |
8 |
Correct |
168 ms |
13316 KB |
Output is correct |
9 |
Correct |
185 ms |
14228 KB |
Output is correct |
10 |
Correct |
178 ms |
14260 KB |
Output is correct |
11 |
Correct |
180 ms |
14220 KB |
Output is correct |
12 |
Correct |
177 ms |
14248 KB |
Output is correct |
13 |
Correct |
174 ms |
14288 KB |
Output is correct |
14 |
Correct |
176 ms |
14336 KB |
Output is correct |
15 |
Correct |
182 ms |
14292 KB |
Output is correct |
16 |
Correct |
183 ms |
14408 KB |
Output is correct |
17 |
Correct |
168 ms |
13912 KB |
Output is correct |
18 |
Correct |
177 ms |
13940 KB |
Output is correct |
19 |
Correct |
187 ms |
14044 KB |
Output is correct |
20 |
Correct |
177 ms |
13976 KB |
Output is correct |
21 |
Correct |
187 ms |
14020 KB |
Output is correct |
22 |
Correct |
183 ms |
13928 KB |
Output is correct |
23 |
Correct |
161 ms |
12072 KB |
Output is correct |
24 |
Correct |
173 ms |
11848 KB |
Output is correct |
25 |
Correct |
173 ms |
12332 KB |
Output is correct |
26 |
Correct |
168 ms |
12280 KB |
Output is correct |
27 |
Correct |
185 ms |
13032 KB |
Output is correct |
28 |
Correct |
176 ms |
13196 KB |
Output is correct |
29 |
Correct |
181 ms |
13072 KB |
Output is correct |
30 |
Correct |
179 ms |
13000 KB |
Output is correct |
31 |
Correct |
168 ms |
11920 KB |
Output is correct |
32 |
Correct |
186 ms |
11788 KB |
Output is correct |
33 |
Correct |
163 ms |
12156 KB |
Output is correct |
34 |
Correct |
172 ms |
12276 KB |
Output is correct |
35 |
Correct |
178 ms |
13000 KB |
Output is correct |
36 |
Correct |
174 ms |
13024 KB |
Output is correct |
37 |
Correct |
166 ms |
12844 KB |
Output is correct |
38 |
Correct |
183 ms |
13012 KB |
Output is correct |
39 |
Correct |
178 ms |
12892 KB |
Output is correct |
40 |
Correct |
172 ms |
12828 KB |
Output is correct |
41 |
Correct |
186 ms |
13556 KB |
Output is correct |
42 |
Correct |
179 ms |
13420 KB |
Output is correct |
43 |
Correct |
175 ms |
13596 KB |
Output is correct |
44 |
Correct |
181 ms |
13504 KB |
Output is correct |
45 |
Correct |
176 ms |
13488 KB |
Output is correct |
46 |
Correct |
176 ms |
13544 KB |
Output is correct |
47 |
Correct |
174 ms |
12700 KB |
Output is correct |
48 |
Correct |
170 ms |
12764 KB |
Output is correct |
49 |
Correct |
189 ms |
12692 KB |
Output is correct |
50 |
Correct |
178 ms |
12776 KB |
Output is correct |
51 |
Correct |
170 ms |
12060 KB |
Output is correct |
52 |
Correct |
197 ms |
12060 KB |
Output is correct |
53 |
Correct |
163 ms |
12156 KB |
Output is correct |
54 |
Correct |
183 ms |
12028 KB |
Output is correct |
55 |
Correct |
168 ms |
12032 KB |
Output is correct |
56 |
Correct |
159 ms |
11944 KB |
Output is correct |
57 |
Correct |
163 ms |
11908 KB |
Output is correct |
58 |
Correct |
181 ms |
12168 KB |
Output is correct |
59 |
Correct |
178 ms |
12088 KB |
Output is correct |
60 |
Correct |
178 ms |
12080 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
178 ms |
11636 KB |
Output is correct |
2 |
Correct |
170 ms |
12424 KB |
Output is correct |
3 |
Correct |
1 ms |
1032 KB |
Output is correct |
4 |
Correct |
163 ms |
11676 KB |
Output is correct |
5 |
Correct |
200 ms |
14260 KB |
Output is correct |
6 |
Correct |
176 ms |
14384 KB |
Output is correct |
7 |
Correct |
176 ms |
13288 KB |
Output is correct |
8 |
Correct |
179 ms |
13296 KB |
Output is correct |
9 |
Correct |
178 ms |
14252 KB |
Output is correct |
10 |
Correct |
173 ms |
14240 KB |
Output is correct |
11 |
Correct |
170 ms |
14404 KB |
Output is correct |
12 |
Correct |
181 ms |
14256 KB |
Output is correct |
13 |
Correct |
179 ms |
14204 KB |
Output is correct |
14 |
Correct |
180 ms |
14276 KB |
Output is correct |
15 |
Correct |
175 ms |
14252 KB |
Output is correct |
16 |
Correct |
186 ms |
14268 KB |
Output is correct |
17 |
Correct |
179 ms |
14020 KB |
Output is correct |
18 |
Correct |
173 ms |
14004 KB |
Output is correct |
19 |
Correct |
175 ms |
13932 KB |
Output is correct |
20 |
Correct |
175 ms |
14080 KB |
Output is correct |
21 |
Correct |
188 ms |
14036 KB |
Output is correct |
22 |
Correct |
177 ms |
13952 KB |
Output is correct |
23 |
Correct |
168 ms |
12156 KB |
Output is correct |
24 |
Correct |
168 ms |
11792 KB |
Output is correct |
25 |
Correct |
170 ms |
12328 KB |
Output is correct |
26 |
Correct |
163 ms |
12248 KB |
Output is correct |
27 |
Correct |
172 ms |
13084 KB |
Output is correct |
28 |
Correct |
180 ms |
13112 KB |
Output is correct |
29 |
Correct |
169 ms |
13120 KB |
Output is correct |
30 |
Correct |
187 ms |
13084 KB |
Output is correct |
31 |
Correct |
188 ms |
11812 KB |
Output is correct |
32 |
Correct |
167 ms |
11800 KB |
Output is correct |
33 |
Correct |
175 ms |
12264 KB |
Output is correct |
34 |
Correct |
183 ms |
12344 KB |
Output is correct |
35 |
Correct |
188 ms |
12812 KB |
Output is correct |
36 |
Correct |
167 ms |
12828 KB |
Output is correct |
37 |
Correct |
177 ms |
12840 KB |
Output is correct |
38 |
Correct |
180 ms |
13048 KB |
Output is correct |
39 |
Correct |
169 ms |
12892 KB |
Output is correct |
40 |
Correct |
190 ms |
12944 KB |
Output is correct |
41 |
Correct |
170 ms |
13844 KB |
Output is correct |
42 |
Correct |
175 ms |
13568 KB |
Output is correct |
43 |
Correct |
186 ms |
13684 KB |
Output is correct |
44 |
Correct |
170 ms |
13552 KB |
Output is correct |
45 |
Correct |
192 ms |
13560 KB |
Output is correct |
46 |
Correct |
166 ms |
13628 KB |
Output is correct |
47 |
Correct |
168 ms |
13024 KB |
Output is correct |
48 |
Correct |
167 ms |
13036 KB |
Output is correct |
49 |
Correct |
193 ms |
12640 KB |
Output is correct |
50 |
Correct |
181 ms |
12768 KB |
Output is correct |
51 |
Correct |
183 ms |
12268 KB |
Output is correct |
52 |
Correct |
164 ms |
12156 KB |
Output is correct |
53 |
Correct |
175 ms |
12156 KB |
Output is correct |
54 |
Correct |
174 ms |
12104 KB |
Output is correct |
55 |
Correct |
168 ms |
11960 KB |
Output is correct |
56 |
Correct |
182 ms |
12052 KB |
Output is correct |
57 |
Correct |
173 ms |
11940 KB |
Output is correct |
58 |
Correct |
173 ms |
11936 KB |
Output is correct |
59 |
Correct |
182 ms |
12152 KB |
Output is correct |
60 |
Correct |
173 ms |
12024 KB |
Output is correct |