#include "Anthony.h"
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
namespace {
} // namespace
int f(int x){
return (x == 1 || x == 4 || x == 5);
}
std::vector<int> Mark(int N, int M, int A, int B,
std::vector<int> U, std::vector<int> V) {
vector<int> adjlist[N];
int dist[N];
int p[N];
vector<int> ans;
queue<int> q;
for (int i = 0; i < M; i++){
adjlist[U[i]].push_back(V[i]);
adjlist[V[i]].push_back(U[i]);
}
ans.resize(M);
if (A >= 3){
memset(dist,-1,sizeof(dist));
dist[0] = 0;
p[0] = 0;
q.push(0);
while (q.size()){
int u = q.front(); q.pop();
for (auto v : adjlist[u]){
if (dist[v] == -1){
//printf("%d -> %d\n",u,v);
p[v] = u;
dist[v] = dist[u]+1;
q.push(v);
}
}
}
for (int i = 0; i < M; i++){
if (dist[U[i]] > dist[V[i]]) swap(U[i],V[i]);
int d = (dist[V[i]]-dist[U[i]]);
if (p[V[i]] == U[i]) {
ans[i] = dist[U[i]]%3;
//printf("edge %d-%d, dist %d,%d: mark %d\n",U[i],V[i],dist[U[i]],dist[V[i]],ans[i]);
}
else ans[i] = -1;
}
for (int i = 0; i < M; i++){
if (ans[i] == -1){
ans[i] = dist[U[i]]%3;
//printf("useless edge %d-%d dist %d,%d: mark %d\n",U[i],V[i],dist[U[i]],dist[V[i]],ans[i]);
}
}
}
else{
memset(dist,-1,sizeof(dist));
dist[0] = 0;
p[0] = 0;
q.push(0);
while (q.size()){
int u = q.front(); q.pop();
int branch = adjlist[u].size() > 2;
if (branch){
dist[u] = f(dist[p[u]])^1;
}
for (auto v : adjlist[u]){
if (dist[v] == -1){
//printf("%d -> %d\n",u,v);
p[v] = u;
dist[v] = (dist[u]+1)%6;
q.push(v);
}
}
}
for (int i = 0; i < M; i++){
if (p[U[i]] == V[i]) swap(U[i],V[i]);
ans[i] = f(dist[U[i]]);
//printf("%d %d %d\n",U[i],V[i],ans[i]);
}
}
return ans;
}
#include "Catherine.h"
#include <bits/stdc++.h>
using namespace std;
namespace {
int A, B;
int sure = 0;
vector<int> sofar;
int prv = -2;
} // namespace
void Init(int A, int B) {
::A = A;
::B = B;
}
int Move(std::vector<int> y) {
//printf("new move %d %d, prev %d\n",y[0],y[1],prv);
//printf("wasted %d so far, sure ? %d\n",(int)sofar.size(),sure);
if (A >= 3){
if (prv == -2){
if (y[0] == 0) return prv = y[1]?1:2;
else if (y[1] == 0) return prv = y[2]?2:0;
else if (y[2] == 0) return prv = y[0]?0:1;
}
else{
return prv = (prv+2)%3;
}
}
else{
int total = y[0]+y[1];
int cur = y[0]==1?0:1;
if (sure){
if (total >= 2){
cur = prv^1;
}
return prv = cur;
}
else if (sofar.empty()){
if (total == 1){
sure = true;
return prv = cur;
}
else if (total == 2){
cur = y[0]?0:1;
if (y[cur] == 2) sofar.push_back(cur);
else sofar.push_back(cur^1);
sofar.push_back(cur);
return prv = cur;
}
else{
sure = true;
assert(y[0] != 0 && y[1] != 0);
return prv = cur;
}
}
else if ((int)sofar.size() == 4){
sure = true;
if (total == 0){
return -1;
}
int CUR = 8*sofar[0] + 4*sofar[1] + 2*sofar[2]+sofar[3];
int need = -1;
if (CUR == 9 || CUR == 11 || CUR == 6) need = 0;
else if (CUR == 12 || CUR == 2 || CUR == 5) need = 1;
//printf("so far visited %d %d %d %d -> %d\n",sofar[0],sofar[1],sofar[2],sofar[3],need);
if (need == -1 || y[need] == 0){
return -1;
}
else return prv = need;
}
else{
if (total == 0){
sure = true;
return -1;
}
if (total > 1){
sure = true;
if (y[0] == 0 || y[1] == 0){
return -1;
}
cur = prv^1;
assert(y[cur]);
return prv = cur;
}
else{
sofar.push_back(cur);
return prv = cur;
}
}
}
}
Compilation message
Anthony.cpp: In function 'std::vector<int> Mark(int, int, int, int, std::vector<int>, std::vector<int>)':
Anthony.cpp:41:17: warning: unused variable 'd' [-Wunused-variable]
int d = (dist[V[i]]-dist[U[i]]);
^
Catherine.cpp: In function 'int Move(std::vector<int>)':
Catherine.cpp:92:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
15636 KB |
Output is correct |
2 |
Correct |
9 ms |
784 KB |
Output is correct |
3 |
Correct |
48 ms |
15164 KB |
Output is correct |
4 |
Correct |
67 ms |
16652 KB |
Output is correct |
5 |
Correct |
69 ms |
16812 KB |
Output is correct |
6 |
Correct |
55 ms |
15368 KB |
Output is correct |
7 |
Correct |
53 ms |
15356 KB |
Output is correct |
8 |
Correct |
62 ms |
16240 KB |
Output is correct |
9 |
Correct |
61 ms |
16168 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
15636 KB |
Output is correct |
2 |
Correct |
9 ms |
784 KB |
Output is correct |
3 |
Correct |
48 ms |
15164 KB |
Output is correct |
4 |
Correct |
67 ms |
16652 KB |
Output is correct |
5 |
Correct |
69 ms |
16812 KB |
Output is correct |
6 |
Correct |
55 ms |
15368 KB |
Output is correct |
7 |
Correct |
53 ms |
15356 KB |
Output is correct |
8 |
Correct |
62 ms |
16240 KB |
Output is correct |
9 |
Correct |
61 ms |
16168 KB |
Output is correct |
10 |
Correct |
49 ms |
13492 KB |
Output is correct |
11 |
Correct |
54 ms |
13484 KB |
Output is correct |
12 |
Correct |
51 ms |
13744 KB |
Output is correct |
13 |
Correct |
51 ms |
13504 KB |
Output is correct |
14 |
Correct |
52 ms |
13688 KB |
Output is correct |
15 |
Correct |
59 ms |
14048 KB |
Output is correct |
16 |
Correct |
63 ms |
16292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
52 ms |
13200 KB |
Output is correct |
2 |
Correct |
9 ms |
780 KB |
Output is correct |
3 |
Correct |
44 ms |
12828 KB |
Output is correct |
4 |
Correct |
63 ms |
14616 KB |
Output is correct |
5 |
Correct |
65 ms |
14640 KB |
Output is correct |
6 |
Correct |
53 ms |
13196 KB |
Output is correct |
7 |
Correct |
50 ms |
13184 KB |
Output is correct |
8 |
Correct |
59 ms |
13940 KB |
Output is correct |
9 |
Correct |
59 ms |
13952 KB |
Output is correct |
10 |
Correct |
55 ms |
13724 KB |
Output is correct |
11 |
Correct |
56 ms |
13736 KB |
Output is correct |
12 |
Correct |
62 ms |
13716 KB |
Output is correct |
13 |
Correct |
55 ms |
13724 KB |
Output is correct |
14 |
Correct |
57 ms |
13980 KB |
Output is correct |
15 |
Correct |
59 ms |
13976 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
52 ms |
13200 KB |
Output is correct |
2 |
Correct |
9 ms |
780 KB |
Output is correct |
3 |
Correct |
44 ms |
12828 KB |
Output is correct |
4 |
Correct |
63 ms |
14616 KB |
Output is correct |
5 |
Correct |
65 ms |
14640 KB |
Output is correct |
6 |
Correct |
53 ms |
13196 KB |
Output is correct |
7 |
Correct |
50 ms |
13184 KB |
Output is correct |
8 |
Correct |
59 ms |
13940 KB |
Output is correct |
9 |
Correct |
59 ms |
13952 KB |
Output is correct |
10 |
Correct |
55 ms |
13724 KB |
Output is correct |
11 |
Correct |
56 ms |
13736 KB |
Output is correct |
12 |
Correct |
62 ms |
13716 KB |
Output is correct |
13 |
Correct |
55 ms |
13724 KB |
Output is correct |
14 |
Correct |
57 ms |
13980 KB |
Output is correct |
15 |
Correct |
59 ms |
13976 KB |
Output is correct |
16 |
Correct |
46 ms |
11732 KB |
Output is correct |
17 |
Correct |
47 ms |
11752 KB |
Output is correct |
18 |
Correct |
49 ms |
11588 KB |
Output is correct |
19 |
Correct |
48 ms |
11512 KB |
Output is correct |
20 |
Correct |
55 ms |
12532 KB |
Output is correct |
21 |
Correct |
51 ms |
11984 KB |
Output is correct |
22 |
Correct |
55 ms |
14096 KB |
Output is correct |
23 |
Correct |
49 ms |
11688 KB |
Output is correct |
24 |
Correct |
53 ms |
11512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
1260 KB |
Output is correct |
2 |
Correct |
9 ms |
772 KB |
Output is correct |
3 |
Correct |
10 ms |
1128 KB |
Output is correct |
4 |
Correct |
10 ms |
1128 KB |
Output is correct |
5 |
Correct |
10 ms |
1100 KB |
Output is correct |
6 |
Correct |
10 ms |
1384 KB |
Output is correct |
7 |
Correct |
10 ms |
1036 KB |
Output is correct |
8 |
Correct |
10 ms |
1260 KB |
Output is correct |
9 |
Correct |
10 ms |
1132 KB |
Output is correct |
10 |
Correct |
10 ms |
1044 KB |
Output is correct |
11 |
Correct |
10 ms |
1104 KB |
Output is correct |
12 |
Correct |
10 ms |
912 KB |
Output is correct |
13 |
Correct |
10 ms |
1040 KB |
Output is correct |
14 |
Correct |
10 ms |
1232 KB |
Output is correct |
15 |
Correct |
10 ms |
1040 KB |
Output is correct |
16 |
Correct |
10 ms |
1128 KB |
Output is correct |
17 |
Correct |
10 ms |
1124 KB |
Output is correct |
18 |
Correct |
10 ms |
1104 KB |
Output is correct |
19 |
Correct |
12 ms |
1040 KB |
Output is correct |
20 |
Correct |
10 ms |
1132 KB |
Output is correct |
21 |
Correct |
10 ms |
1252 KB |
Output is correct |
22 |
Correct |
10 ms |
1144 KB |
Output is correct |
23 |
Correct |
10 ms |
1124 KB |
Output is correct |
24 |
Correct |
10 ms |
1040 KB |
Output is correct |
25 |
Correct |
10 ms |
1128 KB |
Output is correct |
26 |
Correct |
10 ms |
1124 KB |
Output is correct |
27 |
Correct |
12 ms |
1128 KB |
Output is correct |
28 |
Correct |
10 ms |
1268 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
11524 KB |
Output is correct |
2 |
Correct |
53 ms |
11780 KB |
Output is correct |
3 |
Correct |
10 ms |
772 KB |
Output is correct |
4 |
Correct |
43 ms |
11264 KB |
Output is correct |
5 |
Correct |
62 ms |
12532 KB |
Output is correct |
6 |
Correct |
57 ms |
12540 KB |
Output is correct |
7 |
Correct |
52 ms |
11772 KB |
Output is correct |
8 |
Correct |
56 ms |
11772 KB |
Output is correct |
9 |
Correct |
66 ms |
13012 KB |
Output is correct |
10 |
Correct |
59 ms |
13088 KB |
Output is correct |
11 |
Correct |
61 ms |
13160 KB |
Output is correct |
12 |
Correct |
59 ms |
13228 KB |
Output is correct |
13 |
Correct |
57 ms |
13100 KB |
Output is correct |
14 |
Correct |
59 ms |
13080 KB |
Output is correct |
15 |
Correct |
59 ms |
13216 KB |
Output is correct |
16 |
Correct |
61 ms |
13076 KB |
Output is correct |
17 |
Correct |
55 ms |
12840 KB |
Output is correct |
18 |
Correct |
56 ms |
12628 KB |
Output is correct |
19 |
Correct |
57 ms |
12800 KB |
Output is correct |
20 |
Correct |
55 ms |
12832 KB |
Output is correct |
21 |
Correct |
59 ms |
12836 KB |
Output is correct |
22 |
Correct |
56 ms |
12748 KB |
Output is correct |
23 |
Correct |
51 ms |
11904 KB |
Output is correct |
24 |
Correct |
57 ms |
11912 KB |
Output is correct |
25 |
Correct |
50 ms |
12044 KB |
Output is correct |
26 |
Correct |
51 ms |
12040 KB |
Output is correct |
27 |
Correct |
54 ms |
12564 KB |
Output is correct |
28 |
Correct |
55 ms |
12568 KB |
Output is correct |
29 |
Correct |
56 ms |
12500 KB |
Output is correct |
30 |
Correct |
55 ms |
12320 KB |
Output is correct |
31 |
Correct |
50 ms |
11920 KB |
Output is correct |
32 |
Correct |
48 ms |
11916 KB |
Output is correct |
33 |
Correct |
49 ms |
12012 KB |
Output is correct |
34 |
Correct |
50 ms |
12024 KB |
Output is correct |
35 |
Correct |
54 ms |
12284 KB |
Output is correct |
36 |
Correct |
54 ms |
12440 KB |
Output is correct |
37 |
Correct |
54 ms |
12436 KB |
Output is correct |
38 |
Correct |
54 ms |
12432 KB |
Output is correct |
39 |
Correct |
54 ms |
12432 KB |
Output is correct |
40 |
Correct |
55 ms |
12440 KB |
Output is correct |
41 |
Correct |
57 ms |
12716 KB |
Output is correct |
42 |
Correct |
55 ms |
12708 KB |
Output is correct |
43 |
Correct |
57 ms |
12612 KB |
Output is correct |
44 |
Correct |
59 ms |
12692 KB |
Output is correct |
45 |
Correct |
55 ms |
12708 KB |
Output is correct |
46 |
Correct |
55 ms |
12704 KB |
Output is correct |
47 |
Correct |
53 ms |
12300 KB |
Output is correct |
48 |
Correct |
52 ms |
12304 KB |
Output is correct |
49 |
Correct |
52 ms |
12172 KB |
Output is correct |
50 |
Correct |
53 ms |
12432 KB |
Output is correct |
51 |
Correct |
49 ms |
12184 KB |
Output is correct |
52 |
Correct |
51 ms |
12180 KB |
Output is correct |
53 |
Correct |
50 ms |
12160 KB |
Output is correct |
54 |
Correct |
49 ms |
12236 KB |
Output is correct |
55 |
Correct |
49 ms |
12180 KB |
Output is correct |
56 |
Correct |
50 ms |
12280 KB |
Output is correct |
57 |
Correct |
49 ms |
12180 KB |
Output is correct |
58 |
Correct |
52 ms |
12180 KB |
Output is correct |
59 |
Correct |
50 ms |
12196 KB |
Output is correct |
60 |
Correct |
50 ms |
12168 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
11512 KB |
Output is correct |
2 |
Correct |
52 ms |
11772 KB |
Output is correct |
3 |
Correct |
8 ms |
784 KB |
Output is correct |
4 |
Correct |
48 ms |
11376 KB |
Output is correct |
5 |
Correct |
57 ms |
12704 KB |
Output is correct |
6 |
Correct |
57 ms |
12592 KB |
Output is correct |
7 |
Correct |
54 ms |
11820 KB |
Output is correct |
8 |
Correct |
55 ms |
11820 KB |
Output is correct |
9 |
Correct |
59 ms |
12580 KB |
Output is correct |
10 |
Correct |
60 ms |
12700 KB |
Output is correct |
11 |
Correct |
59 ms |
13088 KB |
Output is correct |
12 |
Correct |
63 ms |
13208 KB |
Output is correct |
13 |
Correct |
63 ms |
13224 KB |
Output is correct |
14 |
Correct |
60 ms |
13208 KB |
Output is correct |
15 |
Correct |
64 ms |
13188 KB |
Output is correct |
16 |
Correct |
59 ms |
13228 KB |
Output is correct |
17 |
Correct |
57 ms |
12752 KB |
Output is correct |
18 |
Correct |
56 ms |
12820 KB |
Output is correct |
19 |
Correct |
56 ms |
12828 KB |
Output is correct |
20 |
Correct |
57 ms |
12836 KB |
Output is correct |
21 |
Correct |
55 ms |
12844 KB |
Output is correct |
22 |
Correct |
55 ms |
12808 KB |
Output is correct |
23 |
Correct |
49 ms |
11868 KB |
Output is correct |
24 |
Correct |
52 ms |
11900 KB |
Output is correct |
25 |
Correct |
52 ms |
12164 KB |
Output is correct |
26 |
Correct |
50 ms |
12116 KB |
Output is correct |
27 |
Correct |
55 ms |
12572 KB |
Output is correct |
28 |
Correct |
55 ms |
12560 KB |
Output is correct |
29 |
Correct |
54 ms |
12556 KB |
Output is correct |
30 |
Correct |
56 ms |
12532 KB |
Output is correct |
31 |
Correct |
48 ms |
11884 KB |
Output is correct |
32 |
Correct |
49 ms |
11876 KB |
Output is correct |
33 |
Correct |
48 ms |
12032 KB |
Output is correct |
34 |
Correct |
53 ms |
12152 KB |
Output is correct |
35 |
Correct |
53 ms |
12364 KB |
Output is correct |
36 |
Correct |
53 ms |
12432 KB |
Output is correct |
37 |
Correct |
55 ms |
12572 KB |
Output is correct |
38 |
Correct |
62 ms |
12408 KB |
Output is correct |
39 |
Correct |
54 ms |
12412 KB |
Output is correct |
40 |
Correct |
54 ms |
12284 KB |
Output is correct |
41 |
Correct |
56 ms |
12704 KB |
Output is correct |
42 |
Correct |
55 ms |
12500 KB |
Output is correct |
43 |
Correct |
56 ms |
12688 KB |
Output is correct |
44 |
Correct |
55 ms |
12804 KB |
Output is correct |
45 |
Correct |
62 ms |
12956 KB |
Output is correct |
46 |
Correct |
66 ms |
12788 KB |
Output is correct |
47 |
Correct |
52 ms |
12288 KB |
Output is correct |
48 |
Correct |
53 ms |
12416 KB |
Output is correct |
49 |
Correct |
53 ms |
12308 KB |
Output is correct |
50 |
Correct |
52 ms |
12252 KB |
Output is correct |
51 |
Correct |
50 ms |
12172 KB |
Output is correct |
52 |
Correct |
50 ms |
12136 KB |
Output is correct |
53 |
Correct |
50 ms |
12152 KB |
Output is correct |
54 |
Correct |
51 ms |
12172 KB |
Output is correct |
55 |
Correct |
50 ms |
12116 KB |
Output is correct |
56 |
Correct |
54 ms |
12188 KB |
Output is correct |
57 |
Correct |
56 ms |
12188 KB |
Output is correct |
58 |
Correct |
51 ms |
12300 KB |
Output is correct |
59 |
Correct |
49 ms |
12176 KB |
Output is correct |
60 |
Correct |
51 ms |
12172 KB |
Output is correct |