#include "Anthony.h"
#include <bits/stdc++.h>
#define Loop(x, l, r) for (ll x = (l); x < (r); ++x)
typedef long long ll;
using namespace std;
namespace {
const int N = 20'010;
vector<int> A[N];
int dis[N];
void bfs() {
memset(dis, -1, sizeof(dis));
vector<int> q = {0};
dis[0] = 0;
Loop (i,0,q.size()) {
int v = q[i];
for (int u : A[v]) {
if (dis[u] == -1) {
dis[u] = dis[v]+1;
q.push_back(u);
}
}
}
}
int height[N];
int val[N];
const int pat[] = {0, 0, 1, 0, 1, 1};
const int pats = sizeof(pat)/sizeof(*pat);
void dfs(int v, int p, int x, int h) {
height[v] = h;
val[v] = pat[x%pats];
for (int u : A[v]) {
if (u == p)
continue;
if (A[v].size() == 2)
dfs(u, v, x+1, h+1);
else
dfs(u, v, val[v]==0? 2: 0, h+1);
}
}
} // namespace
std::vector<int> Mark(int N, int M, int a, int b,
std::vector<int> U, std::vector<int> V) {
Loop (i,0,M) {
int v = V[i], u = U[i];
A[v].push_back(u);
A[u].push_back(v);
}
vector<int> ans(M);
if (a == 2) {
dfs(0, -1, 0, 0);
Loop (i,0,M) {
int v = V[i], u = U[i];
if (height[v] > height[u])
swap(v, u);
ans[i] = val[u];
}
} else {
bfs();
Loop (i,0,M) {
int v = V[i], u = U[i];
ans[i] = min(dis[v], dis[u]) % 3;
}
}
return ans;
}
#include "Catherine.h"
#include <bits/stdc++.h>
#define Loop(x, l, r) for (ll x = (l); x < (r); ++x)
typedef long long ll;
using namespace std;
namespace {
int (*move_ptr)(vector<int>);
int lst = -1;
int move3(vector<int> y) {
if (y[0] && y[1])
return 0;
if (y[1] && y[2])
return 1;
if (y[2] && y[0])
return 2;
return !!y[1] + 2*!!y[2];
}
int move_up(vector<int> y) {
if (!!y[0] + !!y[1] == 1)
return !!y[1];
if (y[0] + (lst == 0) == 1)
return 0;
else
return 1;
}
const int pat[] = {0, 0, 1, 0, 1, 1};
const int pats = sizeof(pat)/sizeof(*pat);
vector<int> cur_pat;
bool test() {
vector<int> p(pat, pat+pats), q(cur_pat);
Loop (_,0,pats) {
int x = p.back();
p.pop_back();
if (p == q)
return 1;
p.insert(p.begin(), x);
}
return 0;
}
int move_test(vector<int> y) {
if (y[0] + y[1] + (lst != -1) != 2)
return (move_ptr = move_up)(y);
if (cur_pat.size() == 0) {
if (y[0] && y[1]) {
cur_pat = {0, 1};
return 1;
}
if (y[0]) {
cur_pat = {0, 0};
return 0;
} else {
cur_pat = {1, 1};
return 1;
}
}
cur_pat.push_back(!!y[1]);
if (cur_pat.size() == 5) {
move_ptr = move_up;
if (test())
return move_up(y);
else
return -1;
}
return !!y[1];
}
} // namespace
void Init(int A, int B) {
move_ptr = A == 2? move_test: move3;
}
int Move(std::vector<int> y) {
int x = move_ptr(y);
lst = x;
return x;
}
Compilation message
Anthony.cpp: In function 'void {anonymous}::bfs()':
Anthony.cpp:3:42: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
3 | #define Loop(x, l, r) for (ll x = (l); x < (r); ++x)
| ^
Anthony.cpp:16:3: note: in expansion of macro 'Loop'
16 | Loop (i,0,q.size()) {
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
15908 KB |
Output is correct |
2 |
Correct |
2 ms |
1080 KB |
Output is correct |
3 |
Correct |
25 ms |
15132 KB |
Output is correct |
4 |
Correct |
41 ms |
16972 KB |
Output is correct |
5 |
Correct |
44 ms |
16988 KB |
Output is correct |
6 |
Correct |
33 ms |
15720 KB |
Output is correct |
7 |
Correct |
41 ms |
15676 KB |
Output is correct |
8 |
Correct |
37 ms |
16424 KB |
Output is correct |
9 |
Correct |
38 ms |
16352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
15908 KB |
Output is correct |
2 |
Correct |
2 ms |
1080 KB |
Output is correct |
3 |
Correct |
25 ms |
15132 KB |
Output is correct |
4 |
Correct |
41 ms |
16972 KB |
Output is correct |
5 |
Correct |
44 ms |
16988 KB |
Output is correct |
6 |
Correct |
33 ms |
15720 KB |
Output is correct |
7 |
Correct |
41 ms |
15676 KB |
Output is correct |
8 |
Correct |
37 ms |
16424 KB |
Output is correct |
9 |
Correct |
38 ms |
16352 KB |
Output is correct |
10 |
Correct |
27 ms |
13864 KB |
Output is correct |
11 |
Correct |
31 ms |
13876 KB |
Output is correct |
12 |
Correct |
36 ms |
13736 KB |
Output is correct |
13 |
Correct |
29 ms |
13880 KB |
Output is correct |
14 |
Correct |
26 ms |
14052 KB |
Output is correct |
15 |
Correct |
30 ms |
14416 KB |
Output is correct |
16 |
Correct |
51 ms |
16624 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
13468 KB |
Output is correct |
2 |
Correct |
2 ms |
1164 KB |
Output is correct |
3 |
Correct |
24 ms |
12916 KB |
Output is correct |
4 |
Correct |
38 ms |
14932 KB |
Output is correct |
5 |
Correct |
34 ms |
14784 KB |
Output is correct |
6 |
Correct |
30 ms |
13512 KB |
Output is correct |
7 |
Correct |
37 ms |
13500 KB |
Output is correct |
8 |
Correct |
39 ms |
14196 KB |
Output is correct |
9 |
Correct |
33 ms |
14128 KB |
Output is correct |
10 |
Correct |
40 ms |
14040 KB |
Output is correct |
11 |
Correct |
28 ms |
13884 KB |
Output is correct |
12 |
Correct |
36 ms |
13856 KB |
Output is correct |
13 |
Correct |
31 ms |
13872 KB |
Output is correct |
14 |
Correct |
47 ms |
14088 KB |
Output is correct |
15 |
Correct |
35 ms |
14272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
13468 KB |
Output is correct |
2 |
Correct |
2 ms |
1164 KB |
Output is correct |
3 |
Correct |
24 ms |
12916 KB |
Output is correct |
4 |
Correct |
38 ms |
14932 KB |
Output is correct |
5 |
Correct |
34 ms |
14784 KB |
Output is correct |
6 |
Correct |
30 ms |
13512 KB |
Output is correct |
7 |
Correct |
37 ms |
13500 KB |
Output is correct |
8 |
Correct |
39 ms |
14196 KB |
Output is correct |
9 |
Correct |
33 ms |
14128 KB |
Output is correct |
10 |
Correct |
40 ms |
14040 KB |
Output is correct |
11 |
Correct |
28 ms |
13884 KB |
Output is correct |
12 |
Correct |
36 ms |
13856 KB |
Output is correct |
13 |
Correct |
31 ms |
13872 KB |
Output is correct |
14 |
Correct |
47 ms |
14088 KB |
Output is correct |
15 |
Correct |
35 ms |
14272 KB |
Output is correct |
16 |
Correct |
31 ms |
11888 KB |
Output is correct |
17 |
Correct |
27 ms |
11840 KB |
Output is correct |
18 |
Correct |
26 ms |
11824 KB |
Output is correct |
19 |
Correct |
26 ms |
11952 KB |
Output is correct |
20 |
Correct |
30 ms |
12516 KB |
Output is correct |
21 |
Correct |
27 ms |
12268 KB |
Output is correct |
22 |
Correct |
34 ms |
14336 KB |
Output is correct |
23 |
Correct |
27 ms |
11988 KB |
Output is correct |
24 |
Correct |
25 ms |
11988 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1288 KB |
Output is correct |
2 |
Correct |
2 ms |
1028 KB |
Output is correct |
3 |
Correct |
2 ms |
1292 KB |
Output is correct |
4 |
Correct |
2 ms |
1420 KB |
Output is correct |
5 |
Correct |
2 ms |
1296 KB |
Output is correct |
6 |
Incorrect |
2 ms |
1416 KB |
Wrong Answer [5] |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
11468 KB |
Output is correct |
2 |
Incorrect |
26 ms |
12424 KB |
Wrong Answer [5] |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
23 ms |
11532 KB |
Wrong Answer [5] |
2 |
Halted |
0 ms |
0 KB |
- |