Submission #212289

# Submission time Handle Problem Language Result Execution time Memory
212289 2020-03-22T16:39:59 Z ksun48 Stray Cat (JOI20_stray) C++14
100 / 100
121 ms 16828 KB
#include "Anthony.h"
#include <vector>
#include <bits/stdc++.h>

namespace {
	using namespace std;
	vector<vector<pair<int,int> > > edges;
	vector<int> marks;
	vector<int> arr = {0, 1, 0, 0, 1, 1};

	void dfs(int v, int pid, int idx){
		if(pid >= 0) marks[pid] = arr[idx];
		for(pair<int,int> e : edges[v]){
			if(e.second == pid) continue;
			if(edges[v].size() == 2){
				dfs(e.first, e.second, (idx + 1) % 6);
			} else {
				dfs(e.first, e.second, 1 ^ arr[idx]);
			}
		}
	}
	void mark_tree(int n, int m, vector<int> u, vector<int> v){
		edges.assign(n, {});
		for(int i = 0; i < m; i++){
			edges[u[i]].push_back({v[i], i});
			edges[v[i]].push_back({u[i], i});
		}
		marks.resize(m);
		dfs(0, -1, 0);
	}

	void mark_bfs(int n, int m, vector<int> u, vector<int> v){
		vector<vector<int> > e(n);
		for(int i = 0; i < m; i++){
			e[u[i]].push_back(v[i]);
			e[v[i]].push_back(u[i]);
		}
		vector<int> dist(n, -1);
		vector<int> bfs;
		int s = 0;
		bfs.push_back(0);
		dist[0] = 0;
		while(s < (int)bfs.size()){
			int x = bfs[s];
			s++;
			for(int w : e[x]){
				if(dist[w] >= 0) continue;
				dist[w] = dist[x] + 1;
				bfs.push_back(w);
			}
		}
		marks.resize(m);
		for(int i = 0; i < m; i++){
			marks[i] = min(dist[u[i]], dist[v[i]]) % 3;
		}
	}
	vector<int> mark(int n, int m, int a, int b, vector<int> u, vector<int> v){
		if(b > 0){
			mark_tree(n, m, u, v);
		} else {
			mark_bfs(n, m, u, v);
		}
		return marks;
	}
}  // namespace

std::vector<int> Mark(int N, int M, int A, int B, std::vector<int> U, std::vector<int> V) {
	return mark(N, M, A, B, U, V);
}
#include "Catherine.h"
#include <vector>
#include <bits/stdc++.h>

namespace {
	using namespace std;
	int a;
	int b;
	int last;
	vector<int> seen;
	bool good_to_go;
	void init(int _a, int _b){
		a = _a;
		b = _b;
		last = -1;
		good_to_go = false;
	}
	int move_tree(vector<int> y){
		vector<int> newy = y;
		if(last >= 0) newy[last]++;
		int deg = 0;
		for(int x : newy) deg += x;
		if(deg != 2){
			good_to_go = true;
		}
		if(good_to_go){
			if(deg == 1){
				if(last == -1){
					int r = 0;
					while(y[r] != 1) r++;
					last = r;
					return r;
				}
				return -1;
			} else if(deg == 2){
				assert(last != -1);
				int r = 0;
				while(y[r] != 1) r++;
				last = r;
				return r;
			} else {
				int r = 0;
				while(newy[r] != 1) r++;
				if(y[r] != 1){
					return -1;
				} else {
					last = r;
					return r;
				}
			}
		} else {
			assert(seen.size() < 5);
			if(last == -1){
				int r = 0;
				while(y[r] == 0) r++;
				seen.push_back(r);
				y[r]--;
				r = 0;
				while(y[r] == 0) r++;
				last = r;
				seen.push_back(r);
				return r;
			} else {
				int r = 0;
				while(y[r] == 0) r++;
				seen.push_back(r);
				if(seen.size() < 5){
					last = r;
					return r;
				} else {
					good_to_go = true;
					vector<vector<int> > okay = {
						{1, 1, 0, 0, 1},
						{1, 0, 0, 1, 0},
						{0, 0, 1, 0, 1},
						{0, 1, 0, 1, 1},
						{1, 0, 1, 1, 0},
						{0, 1, 1, 0, 0},
					};
					for(vector<int> v : okay){
						if(v == seen){
							last = r;
							return r;
						}
					}
					return -1;
				}
			}
		}
	}
	int move_bfs(vector<int> y){
		if(last >= 0){
			y[last]++;
		}
		for(int r = 0; r < 3; r++){
			if(y[r] && y[(r+1)%3]){
				assert(last != r);
				last = r;
				return last;
			}
		}
		int r = 0;
		while(y[r] == 0) r++;
		assert(last != r);
		last = r;
		return r;
	}
	int move(vector<int> y){
		if(b == 0){
			return move_bfs(y);
		} else {
			return move_tree(y);
		}
	}

}  // namespace

void Init(int A, int B) {
	init(A, B);
}

int Move(std::vector<int> y) {
	return move(y);
}
# Verdict Execution time Memory Grader output
1 Correct 70 ms 15620 KB Output is correct
2 Correct 10 ms 884 KB Output is correct
3 Correct 54 ms 14976 KB Output is correct
4 Correct 78 ms 16724 KB Output is correct
5 Correct 72 ms 16828 KB Output is correct
6 Correct 72 ms 15412 KB Output is correct
7 Correct 62 ms 15480 KB Output is correct
8 Correct 77 ms 16144 KB Output is correct
9 Correct 74 ms 16144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 70 ms 15620 KB Output is correct
2 Correct 10 ms 884 KB Output is correct
3 Correct 54 ms 14976 KB Output is correct
4 Correct 78 ms 16724 KB Output is correct
5 Correct 72 ms 16828 KB Output is correct
6 Correct 72 ms 15412 KB Output is correct
7 Correct 62 ms 15480 KB Output is correct
8 Correct 77 ms 16144 KB Output is correct
9 Correct 74 ms 16144 KB Output is correct
10 Correct 62 ms 13328 KB Output is correct
11 Correct 55 ms 13484 KB Output is correct
12 Correct 57 ms 13448 KB Output is correct
13 Correct 73 ms 13384 KB Output is correct
14 Correct 53 ms 13700 KB Output is correct
15 Correct 69 ms 14072 KB Output is correct
16 Correct 64 ms 16244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 13288 KB Output is correct
2 Correct 10 ms 772 KB Output is correct
3 Correct 51 ms 12688 KB Output is correct
4 Correct 74 ms 14580 KB Output is correct
5 Correct 93 ms 14564 KB Output is correct
6 Correct 54 ms 13292 KB Output is correct
7 Correct 59 ms 13296 KB Output is correct
8 Correct 72 ms 13952 KB Output is correct
9 Correct 72 ms 13940 KB Output is correct
10 Correct 70 ms 13684 KB Output is correct
11 Correct 63 ms 13708 KB Output is correct
12 Correct 73 ms 13604 KB Output is correct
13 Correct 67 ms 13820 KB Output is correct
14 Correct 69 ms 13912 KB Output is correct
15 Correct 68 ms 13928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 13288 KB Output is correct
2 Correct 10 ms 772 KB Output is correct
3 Correct 51 ms 12688 KB Output is correct
4 Correct 74 ms 14580 KB Output is correct
5 Correct 93 ms 14564 KB Output is correct
6 Correct 54 ms 13292 KB Output is correct
7 Correct 59 ms 13296 KB Output is correct
8 Correct 72 ms 13952 KB Output is correct
9 Correct 72 ms 13940 KB Output is correct
10 Correct 70 ms 13684 KB Output is correct
11 Correct 63 ms 13708 KB Output is correct
12 Correct 73 ms 13604 KB Output is correct
13 Correct 67 ms 13820 KB Output is correct
14 Correct 69 ms 13912 KB Output is correct
15 Correct 68 ms 13928 KB Output is correct
16 Correct 48 ms 11392 KB Output is correct
17 Correct 50 ms 11504 KB Output is correct
18 Correct 53 ms 11640 KB Output is correct
19 Correct 53 ms 11520 KB Output is correct
20 Correct 90 ms 12016 KB Output is correct
21 Correct 82 ms 11900 KB Output is correct
22 Correct 95 ms 14168 KB Output is correct
23 Correct 67 ms 11640 KB Output is correct
24 Correct 59 ms 11592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 1172 KB Output is correct
2 Correct 10 ms 988 KB Output is correct
3 Correct 10 ms 1124 KB Output is correct
4 Correct 12 ms 1164 KB Output is correct
5 Correct 12 ms 1080 KB Output is correct
6 Correct 10 ms 1164 KB Output is correct
7 Correct 11 ms 1036 KB Output is correct
8 Correct 11 ms 964 KB Output is correct
9 Correct 10 ms 1072 KB Output is correct
10 Correct 11 ms 1020 KB Output is correct
11 Correct 10 ms 1076 KB Output is correct
12 Correct 11 ms 1172 KB Output is correct
13 Correct 10 ms 1044 KB Output is correct
14 Correct 10 ms 1100 KB Output is correct
15 Correct 11 ms 1172 KB Output is correct
16 Correct 10 ms 1096 KB Output is correct
17 Correct 11 ms 1164 KB Output is correct
18 Correct 10 ms 1036 KB Output is correct
19 Correct 10 ms 1092 KB Output is correct
20 Correct 10 ms 1056 KB Output is correct
21 Correct 10 ms 1036 KB Output is correct
22 Correct 12 ms 1036 KB Output is correct
23 Correct 12 ms 1020 KB Output is correct
24 Correct 10 ms 1252 KB Output is correct
25 Correct 10 ms 1220 KB Output is correct
26 Correct 10 ms 1092 KB Output is correct
27 Correct 11 ms 1052 KB Output is correct
28 Correct 10 ms 1044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 11712 KB Output is correct
2 Correct 68 ms 12648 KB Output is correct
3 Correct 9 ms 780 KB Output is correct
4 Correct 51 ms 11472 KB Output is correct
5 Correct 71 ms 14076 KB Output is correct
6 Correct 121 ms 14076 KB Output is correct
7 Correct 60 ms 13076 KB Output is correct
8 Correct 58 ms 13052 KB Output is correct
9 Correct 71 ms 14156 KB Output is correct
10 Correct 88 ms 14052 KB Output is correct
11 Correct 82 ms 13940 KB Output is correct
12 Correct 68 ms 13948 KB Output is correct
13 Correct 80 ms 14068 KB Output is correct
14 Correct 74 ms 13964 KB Output is correct
15 Correct 93 ms 14028 KB Output is correct
16 Correct 74 ms 14060 KB Output is correct
17 Correct 62 ms 13684 KB Output is correct
18 Correct 88 ms 13692 KB Output is correct
19 Correct 66 ms 13724 KB Output is correct
20 Correct 66 ms 13700 KB Output is correct
21 Correct 72 ms 13692 KB Output is correct
22 Correct 71 ms 13676 KB Output is correct
23 Correct 49 ms 11720 KB Output is correct
24 Correct 57 ms 11772 KB Output is correct
25 Correct 52 ms 12064 KB Output is correct
26 Correct 64 ms 12276 KB Output is correct
27 Correct 82 ms 12788 KB Output is correct
28 Correct 70 ms 12904 KB Output is correct
29 Correct 82 ms 12916 KB Output is correct
30 Correct 69 ms 12952 KB Output is correct
31 Correct 57 ms 11776 KB Output is correct
32 Correct 57 ms 11868 KB Output is correct
33 Correct 52 ms 12028 KB Output is correct
34 Correct 50 ms 12132 KB Output is correct
35 Correct 74 ms 12788 KB Output is correct
36 Correct 69 ms 12792 KB Output is correct
37 Correct 75 ms 12660 KB Output is correct
38 Correct 59 ms 12796 KB Output is correct
39 Correct 64 ms 12768 KB Output is correct
40 Correct 61 ms 12712 KB Output is correct
41 Correct 61 ms 13368 KB Output is correct
42 Correct 71 ms 13372 KB Output is correct
43 Correct 64 ms 13312 KB Output is correct
44 Correct 71 ms 13308 KB Output is correct
45 Correct 68 ms 13420 KB Output is correct
46 Correct 63 ms 13320 KB Output is correct
47 Correct 62 ms 12592 KB Output is correct
48 Correct 72 ms 12532 KB Output is correct
49 Correct 57 ms 12544 KB Output is correct
50 Correct 67 ms 12668 KB Output is correct
51 Correct 54 ms 11772 KB Output is correct
52 Correct 60 ms 11932 KB Output is correct
53 Correct 52 ms 11892 KB Output is correct
54 Correct 56 ms 11876 KB Output is correct
55 Correct 56 ms 11940 KB Output is correct
56 Correct 63 ms 11892 KB Output is correct
57 Correct 60 ms 11932 KB Output is correct
58 Correct 59 ms 11884 KB Output is correct
59 Correct 64 ms 11876 KB Output is correct
60 Correct 61 ms 12032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 11724 KB Output is correct
2 Correct 63 ms 12656 KB Output is correct
3 Correct 10 ms 908 KB Output is correct
4 Correct 46 ms 11512 KB Output is correct
5 Correct 78 ms 14012 KB Output is correct
6 Correct 73 ms 14120 KB Output is correct
7 Correct 69 ms 13300 KB Output is correct
8 Correct 61 ms 13172 KB Output is correct
9 Correct 83 ms 14044 KB Output is correct
10 Correct 72 ms 14204 KB Output is correct
11 Correct 73 ms 14064 KB Output is correct
12 Correct 75 ms 13928 KB Output is correct
13 Correct 92 ms 13936 KB Output is correct
14 Correct 77 ms 13980 KB Output is correct
15 Correct 75 ms 14076 KB Output is correct
16 Correct 81 ms 14052 KB Output is correct
17 Correct 75 ms 13888 KB Output is correct
18 Correct 89 ms 13764 KB Output is correct
19 Correct 70 ms 14156 KB Output is correct
20 Correct 87 ms 14188 KB Output is correct
21 Correct 73 ms 14308 KB Output is correct
22 Correct 69 ms 14132 KB Output is correct
23 Correct 61 ms 12104 KB Output is correct
24 Correct 53 ms 11992 KB Output is correct
25 Correct 68 ms 12632 KB Output is correct
26 Correct 82 ms 12616 KB Output is correct
27 Correct 87 ms 13260 KB Output is correct
28 Correct 92 ms 13304 KB Output is correct
29 Correct 77 ms 13440 KB Output is correct
30 Correct 77 ms 13396 KB Output is correct
31 Correct 50 ms 12116 KB Output is correct
32 Correct 55 ms 12076 KB Output is correct
33 Correct 60 ms 12580 KB Output is correct
34 Correct 57 ms 12580 KB Output is correct
35 Correct 67 ms 13160 KB Output is correct
36 Correct 61 ms 13268 KB Output is correct
37 Correct 74 ms 13132 KB Output is correct
38 Correct 63 ms 13236 KB Output is correct
39 Correct 66 ms 13212 KB Output is correct
40 Correct 69 ms 13276 KB Output is correct
41 Correct 72 ms 13780 KB Output is correct
42 Correct 75 ms 13764 KB Output is correct
43 Correct 73 ms 13628 KB Output is correct
44 Correct 78 ms 13716 KB Output is correct
45 Correct 88 ms 13876 KB Output is correct
46 Correct 94 ms 13884 KB Output is correct
47 Correct 74 ms 13104 KB Output is correct
48 Correct 95 ms 13068 KB Output is correct
49 Correct 65 ms 12880 KB Output is correct
50 Correct 82 ms 13092 KB Output is correct
51 Correct 67 ms 12380 KB Output is correct
52 Correct 65 ms 12380 KB Output is correct
53 Correct 67 ms 12328 KB Output is correct
54 Correct 62 ms 12380 KB Output is correct
55 Correct 67 ms 12364 KB Output is correct
56 Correct 57 ms 12348 KB Output is correct
57 Correct 62 ms 12108 KB Output is correct
58 Correct 80 ms 12236 KB Output is correct
59 Correct 61 ms 12292 KB Output is correct
60 Correct 62 ms 12116 KB Output is correct