Submission #923712

# Submission time Handle Problem Language Result Execution time Memory
923712 2024-02-07T15:33:43 Z daoquanglinh2007 Stray Cat (JOI20_stray) C++17
100 / 100
53 ms 17276 KB
#include "Anthony.h"
#include <bits/stdc++.h>
using namespace std;

#define isz(a) (int)(a).size()
#define pii pair <int, int>
#define fi first
#define se second
#define mp make_pair

const int NM = 2e4, f[] = {0, 1, 0, 0, 1, 1};

vector <pii> adj[NM+5];
vector <int> ans;
queue <int> q;
int dep[NM+5];

void bfs(){
	for (int i = 0; i < NM; i++) dep[i] = -1;
	dep[0] = 0;
	while (!q.empty()) q.pop();
	q.push(0);
	while (!q.empty()){
		int u = q.front(); q.pop();
		for (pii _ : adj[u]){
			int v = _.fi, id = _.se;
			if (dep[v] != -1){
				ans[id] = dep[v]%3;
			}
			else{
				ans[id] = dep[u]%3;
				dep[v] = dep[u]+1;
				q.push(v);
			}
		}
	}
}

void dfs(int u, int p, int m){
	int child = isz(adj[u])-(p != -1);
	if (child == 1 || p == -1){
		for (pii _ : adj[u]){
			int v = _.fi, id = _.se;
			if (v == p) continue;
			ans[id] = f[m];
			dfs(v, u, (m+1)%6);
		}
	}
	else{
		for (pii _ : adj[u]){
			int v = _.fi, id = _.se;
			if (v == p) continue;
			if (f[(m+5)%6] == 0){
				ans[id] = 1;
				dfs(v, u, 2);
			}
			else{
				ans[id] = 0;
				dfs(v, u, 1);
			}
		}
	}
}

vector <int> Mark(int N, int M, int A, int B, vector <int> U, vector <int> V){
	ans.resize(M);
	for (int i = 0; i < M; i++){
		adj[U[i]].push_back(mp(V[i], i));
		adj[V[i]].push_back(mp(U[i], i));
	}
	if (A > 2){
		bfs();
	}
	else{
		dfs(0, -1, 0);
	}
	return ans;
}
#include "Catherine.h"
#include <bits/stdc++.h>
using namespace std;

int A, B;
int nMove = 0;
bool oriented = 0;
int lst = -1;
string s = "";
int tmp = -1;

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

int Move(vector<int> y){
	if (A > 2){
		if (y[1] == 0 && y[2] == 0) return 0;
		if (y[0] == 0 && y[2] == 0) return 1;
		if (y[0] == 0 && y[1] == 0) return 2;
		if (y[2] == 0) return 0;
		if (y[0] == 0) return 1;
		return 2;
	}
	++nMove;
	if (oriented){
		if (y[0] == 0) return lst = 1, 1;
		if (y[1] == 0) return lst = 0, 0;
		if (lst == 0) return lst = 1, 1;
		return lst = 0, 0;
	}
	if (nMove == 1){
		if (y[0] == 0 && y[1] == 1){
			oriented = 1;
			return lst = 1, 1;
		}
		if (y[1] == 0 && y[0] == 1){
			oriented = 1;
			return lst = 0, 0;
		}
		if (y[1] == 1 && y[0] > 1){
			oriented = 1;
			return lst = 1, 1;
		}
		if (y[0] == 1 && y[1] > 1){
			oriented = 1;
			return lst = 0, 0;
		}
		if (y[0] == 0 && y[1] == 2){
			s.push_back('1');
			tmp = 1;
			return lst = 1, 1;
		}
		if (y[0] == 2 && y[1] == 0){
			s.push_back('0');
			tmp = 0;
			return lst = 0, 0;
		}
		s.push_back('0');
		tmp = 1;
		return lst = 0, 0;
	}
	if (y[0] == 0 && y[1] == 0){
		oriented = 1;
		return -1;
	}
	if (y[0] == 0 && y[1] > 1){
		oriented = 1;
		return -1;
	}
	if (y[1] == 0 && y[0] > 1){
		oriented = 1;
		return -1;
	}
	if (y[0] > 0 && y[1] > 0){
		oriented = 1;
		if (lst == 0) return lst = 1, 1;
		return lst = 0, 0;
	}
	if (nMove < 4){
		if (y[0] > 0){
			s.push_back('0');
			return lst = 0, 0;
		}
		s.push_back('1');
		return lst = 1, 1;
	}
	oriented = 1;
	
	if (s == "001" && y[1] > 0) return -1;
	if (s == "010" && y[0] > 0) return -1;
	if (s == "101" && y[0] > 0) return -1;
	if (s == "110" && y[1] > 0) return -1;
	
	if (s == "100" && y[1] > 0 && tmp == 0) return -1;
	if (s == "011" && y[0] > 0 && tmp == 0) return -1;
	
	if (y[0] > 0) return lst = 0, 0;
	return lst = 1, 1;
}
# Verdict Execution time Memory Grader output
1 Correct 28 ms 16200 KB Output is correct
2 Correct 1 ms 1312 KB Output is correct
3 Correct 28 ms 15500 KB Output is correct
4 Correct 36 ms 17276 KB Output is correct
5 Correct 42 ms 17260 KB Output is correct
6 Correct 28 ms 16032 KB Output is correct
7 Correct 27 ms 15700 KB Output is correct
8 Correct 32 ms 16660 KB Output is correct
9 Correct 32 ms 16992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 16200 KB Output is correct
2 Correct 1 ms 1312 KB Output is correct
3 Correct 28 ms 15500 KB Output is correct
4 Correct 36 ms 17276 KB Output is correct
5 Correct 42 ms 17260 KB Output is correct
6 Correct 28 ms 16032 KB Output is correct
7 Correct 27 ms 15700 KB Output is correct
8 Correct 32 ms 16660 KB Output is correct
9 Correct 32 ms 16992 KB Output is correct
10 Correct 37 ms 14064 KB Output is correct
11 Correct 29 ms 13908 KB Output is correct
12 Correct 25 ms 14184 KB Output is correct
13 Correct 25 ms 14160 KB Output is correct
14 Correct 31 ms 14328 KB Output is correct
15 Correct 36 ms 14616 KB Output is correct
16 Correct 34 ms 16604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 13632 KB Output is correct
2 Correct 1 ms 1312 KB Output is correct
3 Correct 27 ms 13080 KB Output is correct
4 Correct 40 ms 15016 KB Output is correct
5 Correct 31 ms 14936 KB Output is correct
6 Correct 28 ms 13644 KB Output is correct
7 Correct 30 ms 13640 KB Output is correct
8 Correct 38 ms 14396 KB Output is correct
9 Correct 33 ms 14312 KB Output is correct
10 Correct 30 ms 14168 KB Output is correct
11 Correct 31 ms 14080 KB Output is correct
12 Correct 31 ms 14036 KB Output is correct
13 Correct 31 ms 14152 KB Output is correct
14 Correct 32 ms 14400 KB Output is correct
15 Correct 32 ms 14440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 13632 KB Output is correct
2 Correct 1 ms 1312 KB Output is correct
3 Correct 27 ms 13080 KB Output is correct
4 Correct 40 ms 15016 KB Output is correct
5 Correct 31 ms 14936 KB Output is correct
6 Correct 28 ms 13644 KB Output is correct
7 Correct 30 ms 13640 KB Output is correct
8 Correct 38 ms 14396 KB Output is correct
9 Correct 33 ms 14312 KB Output is correct
10 Correct 30 ms 14168 KB Output is correct
11 Correct 31 ms 14080 KB Output is correct
12 Correct 31 ms 14036 KB Output is correct
13 Correct 31 ms 14152 KB Output is correct
14 Correct 32 ms 14400 KB Output is correct
15 Correct 32 ms 14440 KB Output is correct
16 Correct 24 ms 12100 KB Output is correct
17 Correct 24 ms 12100 KB Output is correct
18 Correct 26 ms 12076 KB Output is correct
19 Correct 31 ms 12068 KB Output is correct
20 Correct 30 ms 12876 KB Output is correct
21 Correct 34 ms 12528 KB Output is correct
22 Correct 31 ms 14476 KB Output is correct
23 Correct 25 ms 12356 KB Output is correct
24 Correct 33 ms 12292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1572 KB Output is correct
2 Correct 1 ms 1308 KB Output is correct
3 Correct 2 ms 1572 KB Output is correct
4 Correct 2 ms 1568 KB Output is correct
5 Correct 2 ms 1564 KB Output is correct
6 Correct 2 ms 1564 KB Output is correct
7 Correct 2 ms 1564 KB Output is correct
8 Correct 2 ms 1568 KB Output is correct
9 Correct 2 ms 1568 KB Output is correct
10 Correct 2 ms 1572 KB Output is correct
11 Correct 2 ms 1556 KB Output is correct
12 Correct 2 ms 1568 KB Output is correct
13 Correct 2 ms 1572 KB Output is correct
14 Correct 1 ms 1572 KB Output is correct
15 Correct 1 ms 1572 KB Output is correct
16 Correct 1 ms 2076 KB Output is correct
17 Correct 2 ms 1564 KB Output is correct
18 Correct 1 ms 1564 KB Output is correct
19 Correct 1 ms 1632 KB Output is correct
20 Correct 2 ms 1556 KB Output is correct
21 Correct 2 ms 1564 KB Output is correct
22 Correct 2 ms 1568 KB Output is correct
23 Correct 1 ms 1564 KB Output is correct
24 Correct 1 ms 1560 KB Output is correct
25 Correct 2 ms 1564 KB Output is correct
26 Correct 2 ms 1572 KB Output is correct
27 Correct 2 ms 1612 KB Output is correct
28 Correct 1 ms 1572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 11876 KB Output is correct
2 Correct 27 ms 12860 KB Output is correct
3 Correct 1 ms 1312 KB Output is correct
4 Correct 26 ms 11584 KB Output is correct
5 Correct 33 ms 14152 KB Output is correct
6 Correct 38 ms 14188 KB Output is correct
7 Correct 27 ms 13240 KB Output is correct
8 Correct 35 ms 13292 KB Output is correct
9 Correct 39 ms 14148 KB Output is correct
10 Correct 36 ms 14192 KB Output is correct
11 Correct 35 ms 14244 KB Output is correct
12 Correct 31 ms 14156 KB Output is correct
13 Correct 34 ms 14152 KB Output is correct
14 Correct 32 ms 14164 KB Output is correct
15 Correct 32 ms 14136 KB Output is correct
16 Correct 31 ms 14276 KB Output is correct
17 Correct 36 ms 13904 KB Output is correct
18 Correct 28 ms 13912 KB Output is correct
19 Correct 42 ms 13728 KB Output is correct
20 Correct 33 ms 13836 KB Output is correct
21 Correct 31 ms 13824 KB Output is correct
22 Correct 42 ms 13824 KB Output is correct
23 Correct 26 ms 11896 KB Output is correct
24 Correct 27 ms 11812 KB Output is correct
25 Correct 28 ms 12368 KB Output is correct
26 Correct 26 ms 12356 KB Output is correct
27 Correct 30 ms 13048 KB Output is correct
28 Correct 40 ms 12888 KB Output is correct
29 Correct 33 ms 12872 KB Output is correct
30 Correct 31 ms 12876 KB Output is correct
31 Correct 24 ms 11856 KB Output is correct
32 Correct 25 ms 11796 KB Output is correct
33 Correct 25 ms 12212 KB Output is correct
34 Correct 32 ms 12360 KB Output is correct
35 Correct 30 ms 12784 KB Output is correct
36 Correct 34 ms 12856 KB Output is correct
37 Correct 38 ms 12808 KB Output is correct
38 Correct 42 ms 12856 KB Output is correct
39 Correct 34 ms 12708 KB Output is correct
40 Correct 33 ms 12876 KB Output is correct
41 Correct 31 ms 13388 KB Output is correct
42 Correct 31 ms 13504 KB Output is correct
43 Correct 34 ms 13304 KB Output is correct
44 Correct 35 ms 13304 KB Output is correct
45 Correct 35 ms 13304 KB Output is correct
46 Correct 32 ms 13260 KB Output is correct
47 Correct 36 ms 12752 KB Output is correct
48 Correct 32 ms 12800 KB Output is correct
49 Correct 35 ms 12708 KB Output is correct
50 Correct 27 ms 12824 KB Output is correct
51 Correct 40 ms 11800 KB Output is correct
52 Correct 24 ms 11852 KB Output is correct
53 Correct 32 ms 11964 KB Output is correct
54 Correct 26 ms 11860 KB Output is correct
55 Correct 26 ms 11988 KB Output is correct
56 Correct 26 ms 11888 KB Output is correct
57 Correct 37 ms 12028 KB Output is correct
58 Correct 25 ms 11848 KB Output is correct
59 Correct 31 ms 12008 KB Output is correct
60 Correct 37 ms 11852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 11868 KB Output is correct
2 Correct 33 ms 12744 KB Output is correct
3 Correct 1 ms 1300 KB Output is correct
4 Correct 23 ms 11580 KB Output is correct
5 Correct 43 ms 14068 KB Output is correct
6 Correct 44 ms 14068 KB Output is correct
7 Correct 26 ms 13140 KB Output is correct
8 Correct 35 ms 13180 KB Output is correct
9 Correct 42 ms 14044 KB Output is correct
10 Correct 53 ms 14112 KB Output is correct
11 Correct 42 ms 14200 KB Output is correct
12 Correct 37 ms 13992 KB Output is correct
13 Correct 32 ms 14156 KB Output is correct
14 Correct 36 ms 14156 KB Output is correct
15 Correct 31 ms 14232 KB Output is correct
16 Correct 43 ms 14272 KB Output is correct
17 Correct 32 ms 13836 KB Output is correct
18 Correct 30 ms 13848 KB Output is correct
19 Correct 35 ms 13864 KB Output is correct
20 Correct 36 ms 14028 KB Output is correct
21 Correct 31 ms 13728 KB Output is correct
22 Correct 28 ms 13668 KB Output is correct
23 Correct 27 ms 11860 KB Output is correct
24 Correct 27 ms 11844 KB Output is correct
25 Correct 25 ms 12360 KB Output is correct
26 Correct 28 ms 12368 KB Output is correct
27 Correct 30 ms 12896 KB Output is correct
28 Correct 28 ms 12936 KB Output is correct
29 Correct 27 ms 12936 KB Output is correct
30 Correct 30 ms 12872 KB Output is correct
31 Correct 26 ms 11808 KB Output is correct
32 Correct 24 ms 11848 KB Output is correct
33 Correct 25 ms 12252 KB Output is correct
34 Correct 25 ms 12364 KB Output is correct
35 Correct 28 ms 12872 KB Output is correct
36 Correct 28 ms 12756 KB Output is correct
37 Correct 27 ms 12812 KB Output is correct
38 Correct 27 ms 12852 KB Output is correct
39 Correct 26 ms 12892 KB Output is correct
40 Correct 27 ms 12864 KB Output is correct
41 Correct 31 ms 13344 KB Output is correct
42 Correct 33 ms 13460 KB Output is correct
43 Correct 28 ms 13388 KB Output is correct
44 Correct 28 ms 13620 KB Output is correct
45 Correct 31 ms 13396 KB Output is correct
46 Correct 31 ms 13392 KB Output is correct
47 Correct 40 ms 12836 KB Output is correct
48 Correct 28 ms 12784 KB Output is correct
49 Correct 30 ms 12604 KB Output is correct
50 Correct 27 ms 12864 KB Output is correct
51 Correct 26 ms 11892 KB Output is correct
52 Correct 34 ms 11864 KB Output is correct
53 Correct 28 ms 11844 KB Output is correct
54 Correct 27 ms 11784 KB Output is correct
55 Correct 28 ms 11856 KB Output is correct
56 Correct 26 ms 11820 KB Output is correct
57 Correct 25 ms 11924 KB Output is correct
58 Correct 26 ms 11768 KB Output is correct
59 Correct 26 ms 11900 KB Output is correct
60 Correct 25 ms 11832 KB Output is correct