# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
220390 |
2020-04-07T19:32:43 Z |
WLZ |
Stray Cat (JOI20_stray) |
C++14 |
|
80 ms |
17472 KB |
#include "Anthony.h"
#include <bits/stdc++.h>
using namespace std;
namespace {
const vector<int> period = {0, 1, 0, 0, 1, 1};
struct edge {
int from, to, idx;
};
vector< vector<edge> > g;
vector<int> solve1234(int N, int M, vector<int> U, vector<int> V) {
queue<int> q;
q.push(0);
vector<int> dist(N, -1), ans(M, -1);
dist[0] = 0;
while (!q.empty()) {
int u = q.front(); q.pop();
for (auto& e : g[u]) {
if (dist[e.to] == -1) {
dist[e.to] = dist[u] + 1;
q.push(e.to);
}
}
}
for (int i = 0; i < M; i++) {
ans[i] = min(dist[U[i]], dist[V[i]]) % 3;
}
return ans;
}
vector<int> solve567(int N, int M, vector<int> U, vector<int> V) {
vector<int> prev(N, 1), was(N, 0), len(N, 0), ans(M, -1);
queue<int> q; q.push(0);
was[0] = 1;
while (!q.empty()) {
int u = q.front(); q.pop();
if ((int) g[u].size() == 2) {
if (len[u] == 0) {
if (prev[u] == 0) {
len[u] = 1;
}
}
}
for (auto& e : g[u]) {
if (!was[e.to]) {
if ((int) g[u].size() == 2 || u == 0) {
len[e.to] = len[u] + 1;
ans[e.idx] = period[len[u] % 6];
} else {
ans[e.idx] = !prev[u];
}
q.push(e.to);
was[e.to] = 1;
prev[e.to] = ans[e.idx];
}
}
}
return ans;
}
}
vector<int> Mark(int N, int M, int A, int B, vector<int> U, vector<int> V) {
g.resize(N);
for (int i = 0; i < M; i++) {
g[U[i]].push_back({U[i], V[i], i});
g[V[i]].push_back({V[i], U[i], i});
}
if (A >= 3) {
return solve1234(N, M, U, V);
} else {
return solve567(N, M, U, V);
}
}
#include "Catherine.h"
#include <bits/stdc++.h>
using namespace std;
namespace {
const vector<int> period = {0, 1, 0, 0, 1, 1};
vector<int> cur;
int A, B, start = 1, rev = 0, last;
}
void Init(int A, int B) {
::A = A; ::B = B;
}
int Move(vector<int> y) {
if (A >= 3) {
for (int i = 0; i < 3; i++) {
if (y[i] > 0 && y[(i + 1) % 3] > 0) {
return i;
}
}
for (int i = 0; i < 3; i++) {
if (y[i] > 0) {
return i;
}
}
} else {
if (rev) {
int tmp = cur.back();
cur.pop_back();
if (cur.empty()) {
rev = 0;
}
return (last = tmp);
}
if (y[0] > 1 && y[1] > 0) {
start = 0;
return (last = 1);
}
if (y[0] > 1 && y[1] > 0) {
start = 0;
return (last = 0);
}
if (y[0] == 0 && y[1] == 0) {
start = 0;
return (last = -1);
}
if (start) {
if (y[0] > 0 && y[1] > 0 && !cur.empty()) {
start = 0;
return (last = !cur.back());
}
if (cur.empty()) {
if (y[0] == 1 && y[1] == 0) {
start = 0;
return 0;
}
if (y[1] == 1 && y[0] == 0) {
start = 0;
return 1;
}
}
for (int i = 0; i < 2; i++) {
if (y[i] > 0) {
if (cur.empty()) {
if (y[i] > 1) {
cur.push_back(i);
} else {
cur.push_back(!i);
}
} else if (y[i] > 1) {
start = 0;
return -1;
}
cur.push_back(i);
break;
}
}
if ((int) cur.size() == 5) {
start = 0;
for (int i = 0; i < 6; i++) {
int match = 1;
for (int j = 0; j < 5; j++) {
if (period[(i + j) % 6] != cur[j]) {
match = 0;
break;
}
}
if (match) {
rev = 1;
cur.pop_back();
cur.pop_back();
return -1;
}
}
}
if (!rev) {
return (last = cur.back());
}
} else {
if (y[0] == 1 && y[1] == 1) {
last = !last;
return last;
}
if (y[0] > 0) {
return (last = 0);
}
return (last = 1);
}
}
}
Compilation message
Catherine.cpp: In function 'int Move(std::vector<int>)':
Catherine.cpp:112:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
16400 KB |
Output is correct |
2 |
Correct |
9 ms |
776 KB |
Output is correct |
3 |
Correct |
52 ms |
15740 KB |
Output is correct |
4 |
Correct |
66 ms |
17472 KB |
Output is correct |
5 |
Correct |
69 ms |
17468 KB |
Output is correct |
6 |
Correct |
54 ms |
16104 KB |
Output is correct |
7 |
Correct |
55 ms |
16120 KB |
Output is correct |
8 |
Correct |
62 ms |
16852 KB |
Output is correct |
9 |
Correct |
62 ms |
16716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
16400 KB |
Output is correct |
2 |
Correct |
9 ms |
776 KB |
Output is correct |
3 |
Correct |
52 ms |
15740 KB |
Output is correct |
4 |
Correct |
66 ms |
17472 KB |
Output is correct |
5 |
Correct |
69 ms |
17468 KB |
Output is correct |
6 |
Correct |
54 ms |
16104 KB |
Output is correct |
7 |
Correct |
55 ms |
16120 KB |
Output is correct |
8 |
Correct |
62 ms |
16852 KB |
Output is correct |
9 |
Correct |
62 ms |
16716 KB |
Output is correct |
10 |
Correct |
50 ms |
14164 KB |
Output is correct |
11 |
Correct |
54 ms |
14160 KB |
Output is correct |
12 |
Correct |
52 ms |
14172 KB |
Output is correct |
13 |
Correct |
51 ms |
14172 KB |
Output is correct |
14 |
Correct |
52 ms |
14428 KB |
Output is correct |
15 |
Correct |
63 ms |
14840 KB |
Output is correct |
16 |
Correct |
61 ms |
16960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
13960 KB |
Output is correct |
2 |
Correct |
8 ms |
776 KB |
Output is correct |
3 |
Correct |
45 ms |
13588 KB |
Output is correct |
4 |
Correct |
74 ms |
15284 KB |
Output is correct |
5 |
Correct |
63 ms |
15296 KB |
Output is correct |
6 |
Correct |
51 ms |
13948 KB |
Output is correct |
7 |
Correct |
52 ms |
13900 KB |
Output is correct |
8 |
Correct |
59 ms |
14648 KB |
Output is correct |
9 |
Correct |
56 ms |
14776 KB |
Output is correct |
10 |
Correct |
56 ms |
14496 KB |
Output is correct |
11 |
Correct |
55 ms |
14532 KB |
Output is correct |
12 |
Correct |
55 ms |
14544 KB |
Output is correct |
13 |
Correct |
56 ms |
14380 KB |
Output is correct |
14 |
Correct |
61 ms |
14788 KB |
Output is correct |
15 |
Correct |
60 ms |
14668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
13960 KB |
Output is correct |
2 |
Correct |
8 ms |
776 KB |
Output is correct |
3 |
Correct |
45 ms |
13588 KB |
Output is correct |
4 |
Correct |
74 ms |
15284 KB |
Output is correct |
5 |
Correct |
63 ms |
15296 KB |
Output is correct |
6 |
Correct |
51 ms |
13948 KB |
Output is correct |
7 |
Correct |
52 ms |
13900 KB |
Output is correct |
8 |
Correct |
59 ms |
14648 KB |
Output is correct |
9 |
Correct |
56 ms |
14776 KB |
Output is correct |
10 |
Correct |
56 ms |
14496 KB |
Output is correct |
11 |
Correct |
55 ms |
14532 KB |
Output is correct |
12 |
Correct |
55 ms |
14544 KB |
Output is correct |
13 |
Correct |
56 ms |
14380 KB |
Output is correct |
14 |
Correct |
61 ms |
14788 KB |
Output is correct |
15 |
Correct |
60 ms |
14668 KB |
Output is correct |
16 |
Correct |
46 ms |
12416 KB |
Output is correct |
17 |
Correct |
46 ms |
12436 KB |
Output is correct |
18 |
Correct |
48 ms |
12268 KB |
Output is correct |
19 |
Correct |
49 ms |
12264 KB |
Output is correct |
20 |
Correct |
56 ms |
12916 KB |
Output is correct |
21 |
Correct |
52 ms |
12612 KB |
Output is correct |
22 |
Correct |
61 ms |
14672 KB |
Output is correct |
23 |
Correct |
50 ms |
12388 KB |
Output is correct |
24 |
Correct |
52 ms |
12384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
1040 KB |
Output is correct |
2 |
Correct |
9 ms |
788 KB |
Output is correct |
3 |
Correct |
10 ms |
1116 KB |
Output is correct |
4 |
Correct |
10 ms |
1040 KB |
Output is correct |
5 |
Correct |
10 ms |
1120 KB |
Output is correct |
6 |
Correct |
10 ms |
1120 KB |
Output is correct |
7 |
Correct |
10 ms |
1124 KB |
Output is correct |
8 |
Correct |
10 ms |
1132 KB |
Output is correct |
9 |
Correct |
10 ms |
1104 KB |
Output is correct |
10 |
Correct |
10 ms |
1036 KB |
Output is correct |
11 |
Correct |
10 ms |
1116 KB |
Output is correct |
12 |
Correct |
10 ms |
1124 KB |
Output is correct |
13 |
Correct |
10 ms |
1036 KB |
Output is correct |
14 |
Correct |
10 ms |
1124 KB |
Output is correct |
15 |
Correct |
10 ms |
1120 KB |
Output is correct |
16 |
Correct |
10 ms |
1124 KB |
Output is correct |
17 |
Correct |
10 ms |
1036 KB |
Output is correct |
18 |
Correct |
10 ms |
1128 KB |
Output is correct |
19 |
Correct |
10 ms |
1128 KB |
Output is correct |
20 |
Correct |
10 ms |
1036 KB |
Output is correct |
21 |
Correct |
10 ms |
1128 KB |
Output is correct |
22 |
Correct |
10 ms |
1112 KB |
Output is correct |
23 |
Correct |
10 ms |
1120 KB |
Output is correct |
24 |
Correct |
10 ms |
1124 KB |
Output is correct |
25 |
Correct |
10 ms |
1124 KB |
Output is correct |
26 |
Correct |
10 ms |
1120 KB |
Output is correct |
27 |
Correct |
10 ms |
1244 KB |
Output is correct |
28 |
Correct |
10 ms |
1120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
12440 KB |
Output is correct |
2 |
Correct |
54 ms |
12756 KB |
Output is correct |
3 |
Correct |
9 ms |
780 KB |
Output is correct |
4 |
Correct |
45 ms |
12072 KB |
Output is correct |
5 |
Correct |
59 ms |
13260 KB |
Output is correct |
6 |
Correct |
66 ms |
13608 KB |
Output is correct |
7 |
Correct |
50 ms |
12036 KB |
Output is correct |
8 |
Correct |
50 ms |
11936 KB |
Output is correct |
9 |
Correct |
64 ms |
12956 KB |
Output is correct |
10 |
Correct |
61 ms |
12968 KB |
Output is correct |
11 |
Correct |
61 ms |
12844 KB |
Output is correct |
12 |
Correct |
59 ms |
12852 KB |
Output is correct |
13 |
Correct |
70 ms |
12820 KB |
Output is correct |
14 |
Correct |
60 ms |
12840 KB |
Output is correct |
15 |
Correct |
65 ms |
12960 KB |
Output is correct |
16 |
Correct |
80 ms |
12952 KB |
Output is correct |
17 |
Correct |
56 ms |
12580 KB |
Output is correct |
18 |
Correct |
57 ms |
12540 KB |
Output is correct |
19 |
Correct |
56 ms |
12532 KB |
Output is correct |
20 |
Correct |
56 ms |
12764 KB |
Output is correct |
21 |
Correct |
57 ms |
12576 KB |
Output is correct |
22 |
Correct |
56 ms |
12596 KB |
Output is correct |
23 |
Correct |
49 ms |
11952 KB |
Output is correct |
24 |
Correct |
52 ms |
11988 KB |
Output is correct |
25 |
Correct |
50 ms |
12084 KB |
Output is correct |
26 |
Correct |
50 ms |
12020 KB |
Output is correct |
27 |
Correct |
54 ms |
12404 KB |
Output is correct |
28 |
Correct |
55 ms |
12532 KB |
Output is correct |
29 |
Correct |
55 ms |
12512 KB |
Output is correct |
30 |
Correct |
54 ms |
12536 KB |
Output is correct |
31 |
Correct |
49 ms |
12100 KB |
Output is correct |
32 |
Correct |
50 ms |
12028 KB |
Output is correct |
33 |
Correct |
55 ms |
12148 KB |
Output is correct |
34 |
Correct |
50 ms |
12096 KB |
Output is correct |
35 |
Correct |
56 ms |
12524 KB |
Output is correct |
36 |
Correct |
55 ms |
12524 KB |
Output is correct |
37 |
Correct |
56 ms |
12532 KB |
Output is correct |
38 |
Correct |
55 ms |
12660 KB |
Output is correct |
39 |
Correct |
55 ms |
12656 KB |
Output is correct |
40 |
Correct |
55 ms |
12656 KB |
Output is correct |
41 |
Correct |
56 ms |
12724 KB |
Output is correct |
42 |
Correct |
57 ms |
12556 KB |
Output is correct |
43 |
Correct |
56 ms |
12720 KB |
Output is correct |
44 |
Correct |
55 ms |
12724 KB |
Output is correct |
45 |
Correct |
57 ms |
12724 KB |
Output is correct |
46 |
Correct |
57 ms |
12704 KB |
Output is correct |
47 |
Correct |
53 ms |
12524 KB |
Output is correct |
48 |
Correct |
53 ms |
12516 KB |
Output is correct |
49 |
Correct |
57 ms |
12392 KB |
Output is correct |
50 |
Correct |
53 ms |
12392 KB |
Output is correct |
51 |
Correct |
49 ms |
12084 KB |
Output is correct |
52 |
Correct |
51 ms |
12084 KB |
Output is correct |
53 |
Correct |
51 ms |
12040 KB |
Output is correct |
54 |
Correct |
52 ms |
12260 KB |
Output is correct |
55 |
Correct |
50 ms |
12088 KB |
Output is correct |
56 |
Correct |
50 ms |
12092 KB |
Output is correct |
57 |
Correct |
50 ms |
12284 KB |
Output is correct |
58 |
Correct |
53 ms |
12524 KB |
Output is correct |
59 |
Correct |
50 ms |
12156 KB |
Output is correct |
60 |
Correct |
50 ms |
11920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
12456 KB |
Output is correct |
2 |
Correct |
57 ms |
12912 KB |
Output is correct |
3 |
Correct |
10 ms |
784 KB |
Output is correct |
4 |
Correct |
45 ms |
11956 KB |
Output is correct |
5 |
Correct |
59 ms |
13356 KB |
Output is correct |
6 |
Correct |
59 ms |
13396 KB |
Output is correct |
7 |
Correct |
52 ms |
12596 KB |
Output is correct |
8 |
Correct |
50 ms |
12568 KB |
Output is correct |
9 |
Correct |
62 ms |
13388 KB |
Output is correct |
10 |
Correct |
75 ms |
13260 KB |
Output is correct |
11 |
Correct |
60 ms |
13356 KB |
Output is correct |
12 |
Correct |
64 ms |
13260 KB |
Output is correct |
13 |
Correct |
61 ms |
13464 KB |
Output is correct |
14 |
Correct |
60 ms |
13368 KB |
Output is correct |
15 |
Correct |
63 ms |
13388 KB |
Output is correct |
16 |
Correct |
60 ms |
13336 KB |
Output is correct |
17 |
Correct |
56 ms |
13100 KB |
Output is correct |
18 |
Correct |
56 ms |
13092 KB |
Output is correct |
19 |
Correct |
56 ms |
12948 KB |
Output is correct |
20 |
Correct |
69 ms |
13084 KB |
Output is correct |
21 |
Correct |
59 ms |
13064 KB |
Output is correct |
22 |
Correct |
60 ms |
13092 KB |
Output is correct |
23 |
Correct |
57 ms |
12328 KB |
Output is correct |
24 |
Correct |
49 ms |
12460 KB |
Output is correct |
25 |
Correct |
54 ms |
12400 KB |
Output is correct |
26 |
Correct |
50 ms |
12508 KB |
Output is correct |
27 |
Correct |
60 ms |
12924 KB |
Output is correct |
28 |
Correct |
59 ms |
12888 KB |
Output is correct |
29 |
Correct |
59 ms |
12924 KB |
Output is correct |
30 |
Correct |
55 ms |
12932 KB |
Output is correct |
31 |
Correct |
50 ms |
12476 KB |
Output is correct |
32 |
Correct |
49 ms |
12488 KB |
Output is correct |
33 |
Correct |
50 ms |
12384 KB |
Output is correct |
34 |
Correct |
53 ms |
12388 KB |
Output is correct |
35 |
Correct |
62 ms |
12936 KB |
Output is correct |
36 |
Correct |
59 ms |
12896 KB |
Output is correct |
37 |
Correct |
55 ms |
12756 KB |
Output is correct |
38 |
Correct |
55 ms |
12784 KB |
Output is correct |
39 |
Correct |
58 ms |
12976 KB |
Output is correct |
40 |
Correct |
55 ms |
13008 KB |
Output is correct |
41 |
Correct |
62 ms |
13228 KB |
Output is correct |
42 |
Correct |
56 ms |
13240 KB |
Output is correct |
43 |
Correct |
55 ms |
13140 KB |
Output is correct |
44 |
Correct |
57 ms |
13232 KB |
Output is correct |
45 |
Correct |
59 ms |
13236 KB |
Output is correct |
46 |
Correct |
56 ms |
13228 KB |
Output is correct |
47 |
Correct |
53 ms |
12788 KB |
Output is correct |
48 |
Correct |
57 ms |
12628 KB |
Output is correct |
49 |
Correct |
52 ms |
12660 KB |
Output is correct |
50 |
Correct |
53 ms |
12792 KB |
Output is correct |
51 |
Correct |
53 ms |
12784 KB |
Output is correct |
52 |
Correct |
54 ms |
12608 KB |
Output is correct |
53 |
Correct |
50 ms |
12612 KB |
Output is correct |
54 |
Correct |
50 ms |
12712 KB |
Output is correct |
55 |
Correct |
52 ms |
12588 KB |
Output is correct |
56 |
Correct |
50 ms |
12608 KB |
Output is correct |
57 |
Correct |
53 ms |
12500 KB |
Output is correct |
58 |
Correct |
51 ms |
12532 KB |
Output is correct |
59 |
Correct |
50 ms |
12420 KB |
Output is correct |
60 |
Correct |
52 ms |
12432 KB |
Output is correct |