Submission #514030

# Submission time Handle Problem Language Result Execution time Memory
514030 2022-01-18T02:30:32 Z 8e7 Stray Cat (JOI20_stray) C++17
100 / 100
52 ms 16824 KB
#include "Anthony.h"
#include <vector>
#include <bits/stdc++.h>
#define maxn 20005
#define pii pair<int, int>
using namespace std;
namespace {
	vector<pii> adj[maxn];
	int res[maxn];
	int arr[6] = {0, 0, 1, 0, 1, 1};
	const int inf = 8e7;
	void dfs(int n, int par, int ind, int prv) {
		int deg = adj[n].size() - (par == -1 ? 0 : 1);
		if (deg == 1) {
			for (auto [v, id]:adj[n]) {
				if (v != par) {
					res[id] = arr[ind];
					dfs(v, n, (ind+1)%6, res[id]);
				}
			}
		} else {
			for (auto [v, id]:adj[n]) {
				if (v != par) {
					res[id] = prv ^ 1;
					dfs(v, n, res[id] ? 5 : 1, res[id]);
				}
			}
		}
	}	
}; 

vector<int> Mark(int N, int M, int A, int B,
                      vector<int> U, vector<int> V) {
	for (int i = 0;i < M;i++) adj[U[i]].push_back({V[i], i}), adj[V[i]].push_back({U[i], i});
	vector<int> X(M);
	if (A >= 3) {
		queue<int> que;
		que.push(0);
		vector<int> d(N, inf);
		d[0] = 0;
		while (que.size()) {
			int cur = que.front();que.pop();
			for (auto[v, id] :adj[cur]) {
				if (d[cur] + 1 < d[v]) {
					d[v] = d[cur] + 1;
					que.push(v);
				}
			}
		}
		for (int i = 0; i < M; ++i) {
			if (d[U[i]] > d[V[i]]) swap(U[i], V[i]);
			X[i] = d[U[i]] % 3;
		}
	} else {
		dfs(0, -1, 0, 0);	
		for (int i = 0;i < M;i++) X[i] = res[i];
	}
	return X;
}
#include "Catherine.h"
#include <vector>
#include "assert.h"
using namespace std;

namespace {
	int A, B;
	bool type = 0;
	int prv = 0, step = 0, mask = 0;
	int check[6] = {12, 25, 18, 5, 11, 22};
};  

void Init(int A, int B) {
  ::A = A;
  ::B = B;
}

int Move(vector<int> y) {	
	if (A >= 3) {
		int cnt = (y[0] ? 1 : 0) + (y[1] ? 1 : 0) + (y[2] ? 1 : 0);
		if (cnt == 1) {
			for (int i = 0;i < 3;i++) {
				if (y[i]) return i;
			}
		} else {
			if (y[0] && y[1]) return 0;
			else if (y[1] && y[2]) return 1;
			else if (y[2]) return 2;
		}
		return -1;
	} else {
		int sum = y[0] + y[1];
		sum += (step ? 1 : 0);	
		if (sum > 2) {
			step++;
			if (y[0] == 0 || y[1] == 0) {
				return -1;
			} 
			if (step > 1) y[prv]++;
			prv = y[0] == 1 ? 0 : 1;
			return prv;
		} else {
			if (step) sum--;
			step++;
			if (sum == 1) {
				if (type && step == 4) {
					mask = mask * 2 + (y[0] == 1 ? 0 : 1);
					bool match = 0;
					for (int i = 0;i < 6;i++) {
						if (mask == check[i]) match = 1;
					}	
					if (match) return -1;
				}
				prv = y[0] == 1 ? 0 : 1;
				if (step < 4) mask = mask * 2 + prv;
				return prv;
			} else {
				if (sum == 0) return -1;
				prv = y[0] ? 0 : 1;
				y[prv]--;
				type = 1;
				mask = (y[0] ? 0 : 1) * 2 + prv;
				return prv;	
			}
		}
	}
}
/*
11 10 2 6 6
0 2
0 3
0 4
3 5
5 7
5 8
7 10
4 6
6 9
9 1
*/
# Verdict Execution time Memory Grader output
1 Correct 37 ms 15312 KB Output is correct
2 Correct 1 ms 1068 KB Output is correct
3 Correct 27 ms 15112 KB Output is correct
4 Correct 43 ms 16824 KB Output is correct
5 Correct 43 ms 16816 KB Output is correct
6 Correct 39 ms 15616 KB Output is correct
7 Correct 33 ms 15500 KB Output is correct
8 Correct 39 ms 16280 KB Output is correct
9 Correct 50 ms 16268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 15312 KB Output is correct
2 Correct 1 ms 1068 KB Output is correct
3 Correct 27 ms 15112 KB Output is correct
4 Correct 43 ms 16824 KB Output is correct
5 Correct 43 ms 16816 KB Output is correct
6 Correct 39 ms 15616 KB Output is correct
7 Correct 33 ms 15500 KB Output is correct
8 Correct 39 ms 16280 KB Output is correct
9 Correct 50 ms 16268 KB Output is correct
10 Correct 30 ms 13664 KB Output is correct
11 Correct 33 ms 13704 KB Output is correct
12 Correct 31 ms 13720 KB Output is correct
13 Correct 30 ms 13652 KB Output is correct
14 Correct 38 ms 13796 KB Output is correct
15 Correct 52 ms 14308 KB Output is correct
16 Correct 40 ms 16456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 12920 KB Output is correct
2 Correct 1 ms 1008 KB Output is correct
3 Correct 27 ms 12592 KB Output is correct
4 Correct 43 ms 14316 KB Output is correct
5 Correct 51 ms 14152 KB Output is correct
6 Correct 34 ms 13392 KB Output is correct
7 Correct 32 ms 13456 KB Output is correct
8 Correct 47 ms 14020 KB Output is correct
9 Correct 38 ms 13964 KB Output is correct
10 Correct 40 ms 13824 KB Output is correct
11 Correct 40 ms 13784 KB Output is correct
12 Correct 41 ms 13668 KB Output is correct
13 Correct 40 ms 13808 KB Output is correct
14 Correct 45 ms 14028 KB Output is correct
15 Correct 40 ms 14044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 12920 KB Output is correct
2 Correct 1 ms 1008 KB Output is correct
3 Correct 27 ms 12592 KB Output is correct
4 Correct 43 ms 14316 KB Output is correct
5 Correct 51 ms 14152 KB Output is correct
6 Correct 34 ms 13392 KB Output is correct
7 Correct 32 ms 13456 KB Output is correct
8 Correct 47 ms 14020 KB Output is correct
9 Correct 38 ms 13964 KB Output is correct
10 Correct 40 ms 13824 KB Output is correct
11 Correct 40 ms 13784 KB Output is correct
12 Correct 41 ms 13668 KB Output is correct
13 Correct 40 ms 13808 KB Output is correct
14 Correct 45 ms 14028 KB Output is correct
15 Correct 40 ms 14044 KB Output is correct
16 Correct 28 ms 11876 KB Output is correct
17 Correct 28 ms 11920 KB Output is correct
18 Correct 32 ms 11788 KB Output is correct
19 Correct 34 ms 11740 KB Output is correct
20 Correct 42 ms 12428 KB Output is correct
21 Correct 38 ms 12272 KB Output is correct
22 Correct 40 ms 14112 KB Output is correct
23 Correct 31 ms 11924 KB Output is correct
24 Correct 34 ms 11952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1268 KB Output is correct
2 Correct 1 ms 1008 KB Output is correct
3 Correct 2 ms 1260 KB Output is correct
4 Correct 2 ms 1272 KB Output is correct
5 Correct 2 ms 1264 KB Output is correct
6 Correct 2 ms 1268 KB Output is correct
7 Correct 2 ms 1260 KB Output is correct
8 Correct 2 ms 1260 KB Output is correct
9 Correct 2 ms 1268 KB Output is correct
10 Correct 2 ms 1268 KB Output is correct
11 Correct 2 ms 1268 KB Output is correct
12 Correct 2 ms 1268 KB Output is correct
13 Correct 2 ms 1260 KB Output is correct
14 Correct 2 ms 1268 KB Output is correct
15 Correct 2 ms 1268 KB Output is correct
16 Correct 1 ms 1268 KB Output is correct
17 Correct 2 ms 1260 KB Output is correct
18 Correct 1 ms 1268 KB Output is correct
19 Correct 2 ms 1260 KB Output is correct
20 Correct 2 ms 1268 KB Output is correct
21 Correct 2 ms 1268 KB Output is correct
22 Correct 2 ms 1264 KB Output is correct
23 Correct 2 ms 1260 KB Output is correct
24 Correct 2 ms 1268 KB Output is correct
25 Correct 2 ms 1260 KB Output is correct
26 Correct 1 ms 1260 KB Output is correct
27 Correct 2 ms 1268 KB Output is correct
28 Correct 2 ms 1260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 10976 KB Output is correct
2 Correct 36 ms 12156 KB Output is correct
3 Correct 1 ms 1004 KB Output is correct
4 Correct 27 ms 10912 KB Output is correct
5 Correct 39 ms 13552 KB Output is correct
6 Correct 39 ms 13544 KB Output is correct
7 Correct 32 ms 12720 KB Output is correct
8 Correct 31 ms 12628 KB Output is correct
9 Correct 39 ms 13508 KB Output is correct
10 Correct 39 ms 13656 KB Output is correct
11 Correct 44 ms 13548 KB Output is correct
12 Correct 38 ms 13484 KB Output is correct
13 Correct 39 ms 13464 KB Output is correct
14 Correct 37 ms 13576 KB Output is correct
15 Correct 50 ms 13512 KB Output is correct
16 Correct 36 ms 13532 KB Output is correct
17 Correct 35 ms 13204 KB Output is correct
18 Correct 35 ms 13240 KB Output is correct
19 Correct 39 ms 13212 KB Output is correct
20 Correct 40 ms 13276 KB Output is correct
21 Correct 48 ms 13160 KB Output is correct
22 Correct 36 ms 13216 KB Output is correct
23 Correct 27 ms 11024 KB Output is correct
24 Correct 28 ms 10996 KB Output is correct
25 Correct 31 ms 11420 KB Output is correct
26 Correct 30 ms 11432 KB Output is correct
27 Correct 33 ms 12244 KB Output is correct
28 Correct 36 ms 12240 KB Output is correct
29 Correct 39 ms 12268 KB Output is correct
30 Correct 33 ms 12248 KB Output is correct
31 Correct 28 ms 10944 KB Output is correct
32 Correct 30 ms 10960 KB Output is correct
33 Correct 30 ms 11484 KB Output is correct
34 Correct 30 ms 11512 KB Output is correct
35 Correct 38 ms 12080 KB Output is correct
36 Correct 36 ms 12092 KB Output is correct
37 Correct 37 ms 11992 KB Output is correct
38 Correct 45 ms 11892 KB Output is correct
39 Correct 37 ms 12000 KB Output is correct
40 Correct 33 ms 11932 KB Output is correct
41 Correct 40 ms 12652 KB Output is correct
42 Correct 34 ms 12668 KB Output is correct
43 Correct 35 ms 12720 KB Output is correct
44 Correct 40 ms 12720 KB Output is correct
45 Correct 37 ms 12588 KB Output is correct
46 Correct 39 ms 12612 KB Output is correct
47 Correct 32 ms 11892 KB Output is correct
48 Correct 33 ms 11992 KB Output is correct
49 Correct 36 ms 11824 KB Output is correct
50 Correct 35 ms 12008 KB Output is correct
51 Correct 36 ms 11012 KB Output is correct
52 Correct 33 ms 10980 KB Output is correct
53 Correct 37 ms 10952 KB Output is correct
54 Correct 32 ms 10988 KB Output is correct
55 Correct 31 ms 10960 KB Output is correct
56 Correct 31 ms 10944 KB Output is correct
57 Correct 31 ms 11008 KB Output is correct
58 Correct 30 ms 11088 KB Output is correct
59 Correct 32 ms 11200 KB Output is correct
60 Correct 38 ms 11160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 10908 KB Output is correct
2 Correct 34 ms 11892 KB Output is correct
3 Correct 1 ms 1000 KB Output is correct
4 Correct 26 ms 10908 KB Output is correct
5 Correct 41 ms 13584 KB Output is correct
6 Correct 37 ms 13396 KB Output is correct
7 Correct 31 ms 12592 KB Output is correct
8 Correct 37 ms 12684 KB Output is correct
9 Correct 40 ms 13572 KB Output is correct
10 Correct 41 ms 13592 KB Output is correct
11 Correct 40 ms 13488 KB Output is correct
12 Correct 36 ms 13464 KB Output is correct
13 Correct 37 ms 13532 KB Output is correct
14 Correct 36 ms 13544 KB Output is correct
15 Correct 38 ms 13488 KB Output is correct
16 Correct 37 ms 13508 KB Output is correct
17 Correct 35 ms 13320 KB Output is correct
18 Correct 37 ms 13192 KB Output is correct
19 Correct 47 ms 13196 KB Output is correct
20 Correct 34 ms 13268 KB Output is correct
21 Correct 35 ms 13236 KB Output is correct
22 Correct 34 ms 13152 KB Output is correct
23 Correct 32 ms 10976 KB Output is correct
24 Correct 32 ms 11172 KB Output is correct
25 Correct 36 ms 11452 KB Output is correct
26 Correct 31 ms 11420 KB Output is correct
27 Correct 33 ms 12156 KB Output is correct
28 Correct 36 ms 12152 KB Output is correct
29 Correct 34 ms 12236 KB Output is correct
30 Correct 34 ms 12172 KB Output is correct
31 Correct 31 ms 11016 KB Output is correct
32 Correct 35 ms 10888 KB Output is correct
33 Correct 30 ms 11468 KB Output is correct
34 Correct 31 ms 11456 KB Output is correct
35 Correct 34 ms 12020 KB Output is correct
36 Correct 34 ms 11944 KB Output is correct
37 Correct 37 ms 11948 KB Output is correct
38 Correct 43 ms 11996 KB Output is correct
39 Correct 42 ms 12060 KB Output is correct
40 Correct 40 ms 11952 KB Output is correct
41 Correct 36 ms 12712 KB Output is correct
42 Correct 35 ms 12644 KB Output is correct
43 Correct 35 ms 12756 KB Output is correct
44 Correct 36 ms 12632 KB Output is correct
45 Correct 43 ms 12580 KB Output is correct
46 Correct 37 ms 12736 KB Output is correct
47 Correct 45 ms 11864 KB Output is correct
48 Correct 32 ms 11984 KB Output is correct
49 Correct 33 ms 11880 KB Output is correct
50 Correct 34 ms 11904 KB Output is correct
51 Correct 44 ms 10908 KB Output is correct
52 Correct 31 ms 11020 KB Output is correct
53 Correct 32 ms 10868 KB Output is correct
54 Correct 28 ms 11084 KB Output is correct
55 Correct 34 ms 11048 KB Output is correct
56 Correct 30 ms 11024 KB Output is correct
57 Correct 30 ms 11032 KB Output is correct
58 Correct 30 ms 11172 KB Output is correct
59 Correct 32 ms 11248 KB Output is correct
60 Correct 36 ms 11164 KB Output is correct