Submission #260646

# Submission time Handle Problem Language Result Execution time Memory
260646 2020-08-10T15:58:24 Z Saboon Stray Cat (JOI20_stray) C++14
100 / 100
73 ms 17284 KB
#include "Anthony.h"
#include <bits/stdc++.h>

using namespace std;

const int maxn = 20'000 + 10;

int h[maxn], c[maxn];
vector<int> g[maxn];
int Q[maxn], tail, head;

int seq[] = {1, 1, 0, 0, 1, 0};
int col[maxn];

void dfs(int v, int idx = 0, int par = -1){
	for (int i = 0; i < g[v].size(); i++){
		if (g[v][i] == par){
			g[v].erase(g[v].begin()+i);
			break;
		}
	}
	if (g[v].empty())
		return;
	if (g[v].size() == 1){
		col[g[v][0]] = seq[idx];
		dfs(g[v][0], (idx+1)%6, v);
		return;
	}
	for (auto u : g[v]){
		col[u] = 1-col[v];
		dfs(u, 0, v);
	}
}

void bfs(int v){
	memset(h, -1, sizeof h);
	Q[head++] = v;
	h[v] = 0;
	while (tail < head){
		v = Q[tail++];
		for (auto u : g[v])
			if (h[u] == -1)
				h[u] = h[v]+1, Q[head++] = u;
	}
}

vector<int> Mark(int n, int m, int A, int B, vector<int> U, vector<int> V) {
	vector<int> X(m);
	for (int i = 0; i < m; i++){
		g[U[i]].push_back(V[i]);
		g[V[i]].push_back(U[i]);
	}
	bfs(0);
	if (A >= 3){
		for (int i = 0; i < m; i++){
			int v = V[i], u = U[i];
			if (h[v] == h[u])
				X[i] = h[v]%3;
			else
				X[i] = (max(h[v],h[u])+2)%3;
		}
		return X;
	}
	dfs(0);
	for (int i = 0; i < m; i++){
		int v = V[i], u = U[i];
		if (h[v] > h[u])
			X[i] = col[v];
		else
			X[i] = col[u];
	}
	return X;
}
#include "Catherine.h"
#include <bits/stdc++.h>

using namespace std;

int A, B, last = -1, sure = 0;
string s[] = {"111100", "021001", "110010", "200101", "111011", "110110"};
string now;
bool first;

void Init(int a, int b) {
	A = a, B = b;
	last = -1, sure = 0;
	now.clear();
	first = true;
}


int Move(vector<int> y){
	if (A >= 3){
		int a = -1, b = -1;
		for (int j = 0; j < A; ++j) {
			if (y[j] != 0){
				if (a == -1)
					a = j;
				else
					b = j;
			}
		}
		if (b == -1)
			return a;
		if (a+1 == b)
			return a;
		return b;
	}
	int deg = y[0] + y[1] + (last != -1);
	if (deg == 1){ // we are in a leaf
		sure = true;
		if (last != -1)
			return -1;
		assert(y[y[1]==1] > 0);
		return last = (y[1] == 1);
	}
	if (deg > 2){
		sure = true;
		int nex = ((y[1] + (last==1)) == 1);
		if (last == nex)
			return -1;
		assert(y[nex] > 0);
		return last = nex;
	}
	if (sure){
		assert(y[y[1]==1] > 0);
		return last = (y[1] == 1);
	}
	if (first){
		now += (char)(y[0]+'0');
		now += (char)(y[1]+'0');
		now += (char)((y[1]>0)+'0');
		first = false;
		assert(y[y[1]>0] > 0);
		return last = (y[1] > 0);
	}
	now += (char)((y[1]==1)+'0');
	if (now.size() == 6){
		bool found = 0;
		for (int j = 0; j < 6; j++)
			if (now == s[j])
				found = 1;
		if (now.substr(2, 4) == "1100")
			found = 1;
		sure = 1;
		if (found)
			return -1;
		assert(y[y[1]==1] > 0);
		return last = (y[1] == 1);
	}
	assert(y[y[1]==1] > 0);
	return last = (y[1] == 1);
}

Compilation message

Anthony.cpp: In function 'void dfs(int, int, int)':
Anthony.cpp:16:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < g[v].size(); i++){
                  ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 54 ms 15888 KB Output is correct
2 Correct 1 ms 1792 KB Output is correct
3 Correct 41 ms 15308 KB Output is correct
4 Correct 70 ms 16856 KB Output is correct
5 Correct 68 ms 17284 KB Output is correct
6 Correct 65 ms 15804 KB Output is correct
7 Correct 50 ms 15872 KB Output is correct
8 Correct 60 ms 16576 KB Output is correct
9 Correct 64 ms 16576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 15888 KB Output is correct
2 Correct 1 ms 1792 KB Output is correct
3 Correct 41 ms 15308 KB Output is correct
4 Correct 70 ms 16856 KB Output is correct
5 Correct 68 ms 17284 KB Output is correct
6 Correct 65 ms 15804 KB Output is correct
7 Correct 50 ms 15872 KB Output is correct
8 Correct 60 ms 16576 KB Output is correct
9 Correct 64 ms 16576 KB Output is correct
10 Correct 46 ms 13884 KB Output is correct
11 Correct 49 ms 13756 KB Output is correct
12 Correct 49 ms 13904 KB Output is correct
13 Correct 60 ms 13752 KB Output is correct
14 Correct 50 ms 14144 KB Output is correct
15 Correct 57 ms 14536 KB Output is correct
16 Correct 70 ms 16704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 13640 KB Output is correct
2 Correct 1 ms 1792 KB Output is correct
3 Correct 41 ms 13124 KB Output is correct
4 Correct 72 ms 14912 KB Output is correct
5 Correct 65 ms 15096 KB Output is correct
6 Correct 47 ms 13632 KB Output is correct
7 Correct 53 ms 13596 KB Output is correct
8 Correct 57 ms 14504 KB Output is correct
9 Correct 62 ms 14484 KB Output is correct
10 Correct 53 ms 14484 KB Output is correct
11 Correct 50 ms 14232 KB Output is correct
12 Correct 51 ms 14228 KB Output is correct
13 Correct 52 ms 14144 KB Output is correct
14 Correct 56 ms 14280 KB Output is correct
15 Correct 57 ms 14408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 13640 KB Output is correct
2 Correct 1 ms 1792 KB Output is correct
3 Correct 41 ms 13124 KB Output is correct
4 Correct 72 ms 14912 KB Output is correct
5 Correct 65 ms 15096 KB Output is correct
6 Correct 47 ms 13632 KB Output is correct
7 Correct 53 ms 13596 KB Output is correct
8 Correct 57 ms 14504 KB Output is correct
9 Correct 62 ms 14484 KB Output is correct
10 Correct 53 ms 14484 KB Output is correct
11 Correct 50 ms 14232 KB Output is correct
12 Correct 51 ms 14228 KB Output is correct
13 Correct 52 ms 14144 KB Output is correct
14 Correct 56 ms 14280 KB Output is correct
15 Correct 57 ms 14408 KB Output is correct
16 Correct 45 ms 12200 KB Output is correct
17 Correct 45 ms 12200 KB Output is correct
18 Correct 44 ms 11940 KB Output is correct
19 Correct 44 ms 11980 KB Output is correct
20 Correct 52 ms 12652 KB Output is correct
21 Correct 49 ms 12352 KB Output is correct
22 Correct 55 ms 14616 KB Output is correct
23 Correct 45 ms 12252 KB Output is correct
24 Correct 51 ms 12088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1792 KB Output is correct
2 Correct 2 ms 1792 KB Output is correct
3 Correct 2 ms 1792 KB Output is correct
4 Correct 2 ms 1792 KB Output is correct
5 Correct 2 ms 1792 KB Output is correct
6 Correct 2 ms 1792 KB Output is correct
7 Correct 2 ms 1792 KB Output is correct
8 Correct 2 ms 1792 KB Output is correct
9 Correct 2 ms 1792 KB Output is correct
10 Correct 2 ms 1792 KB Output is correct
11 Correct 2 ms 1792 KB Output is correct
12 Correct 2 ms 1792 KB Output is correct
13 Correct 2 ms 1792 KB Output is correct
14 Correct 2 ms 1792 KB Output is correct
15 Correct 2 ms 1792 KB Output is correct
16 Correct 2 ms 1792 KB Output is correct
17 Correct 2 ms 1792 KB Output is correct
18 Correct 2 ms 1792 KB Output is correct
19 Correct 2 ms 1792 KB Output is correct
20 Correct 2 ms 1792 KB Output is correct
21 Correct 2 ms 1792 KB Output is correct
22 Correct 2 ms 1792 KB Output is correct
23 Correct 2 ms 1792 KB Output is correct
24 Correct 2 ms 1792 KB Output is correct
25 Correct 2 ms 1792 KB Output is correct
26 Correct 2 ms 1792 KB Output is correct
27 Correct 2 ms 1792 KB Output is correct
28 Correct 2 ms 1792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 11840 KB Output is correct
2 Correct 50 ms 12608 KB Output is correct
3 Correct 1 ms 1792 KB Output is correct
4 Correct 38 ms 11768 KB Output is correct
5 Correct 58 ms 13116 KB Output is correct
6 Correct 56 ms 13132 KB Output is correct
7 Correct 45 ms 12360 KB Output is correct
8 Correct 46 ms 12244 KB Output is correct
9 Correct 66 ms 13000 KB Output is correct
10 Correct 62 ms 13016 KB Output is correct
11 Correct 73 ms 12992 KB Output is correct
12 Correct 64 ms 13004 KB Output is correct
13 Correct 60 ms 12992 KB Output is correct
14 Correct 59 ms 13124 KB Output is correct
15 Correct 65 ms 13004 KB Output is correct
16 Correct 66 ms 13120 KB Output is correct
17 Correct 54 ms 12752 KB Output is correct
18 Correct 54 ms 12756 KB Output is correct
19 Correct 58 ms 12820 KB Output is correct
20 Correct 55 ms 12744 KB Output is correct
21 Correct 54 ms 12884 KB Output is correct
22 Correct 54 ms 12784 KB Output is correct
23 Correct 44 ms 11956 KB Output is correct
24 Correct 45 ms 11940 KB Output is correct
25 Correct 47 ms 12212 KB Output is correct
26 Correct 46 ms 12208 KB Output is correct
27 Correct 69 ms 12608 KB Output is correct
28 Correct 50 ms 12780 KB Output is correct
29 Correct 52 ms 12608 KB Output is correct
30 Correct 57 ms 12700 KB Output is correct
31 Correct 45 ms 11952 KB Output is correct
32 Correct 45 ms 11948 KB Output is correct
33 Correct 45 ms 12080 KB Output is correct
34 Correct 45 ms 12156 KB Output is correct
35 Correct 49 ms 12716 KB Output is correct
36 Correct 51 ms 12704 KB Output is correct
37 Correct 55 ms 12752 KB Output is correct
38 Correct 51 ms 12692 KB Output is correct
39 Correct 52 ms 12832 KB Output is correct
40 Correct 50 ms 12616 KB Output is correct
41 Correct 57 ms 12992 KB Output is correct
42 Correct 51 ms 12920 KB Output is correct
43 Correct 52 ms 12864 KB Output is correct
44 Correct 53 ms 12856 KB Output is correct
45 Correct 57 ms 13056 KB Output is correct
46 Correct 61 ms 12908 KB Output is correct
47 Correct 53 ms 12428 KB Output is correct
48 Correct 50 ms 12360 KB Output is correct
49 Correct 60 ms 12352 KB Output is correct
50 Correct 50 ms 12540 KB Output is correct
51 Correct 46 ms 12356 KB Output is correct
52 Correct 46 ms 12376 KB Output is correct
53 Correct 50 ms 12224 KB Output is correct
54 Correct 46 ms 12232 KB Output is correct
55 Correct 46 ms 12232 KB Output is correct
56 Correct 46 ms 12084 KB Output is correct
57 Correct 49 ms 11720 KB Output is correct
58 Correct 46 ms 12112 KB Output is correct
59 Correct 46 ms 12112 KB Output is correct
60 Correct 46 ms 12104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 11948 KB Output is correct
2 Correct 47 ms 12440 KB Output is correct
3 Correct 1 ms 1792 KB Output is correct
4 Correct 38 ms 11768 KB Output is correct
5 Correct 60 ms 13280 KB Output is correct
6 Correct 56 ms 12996 KB Output is correct
7 Correct 45 ms 12096 KB Output is correct
8 Correct 45 ms 12248 KB Output is correct
9 Correct 56 ms 13204 KB Output is correct
10 Correct 54 ms 13000 KB Output is correct
11 Correct 57 ms 13132 KB Output is correct
12 Correct 58 ms 13084 KB Output is correct
13 Correct 63 ms 13000 KB Output is correct
14 Correct 55 ms 13120 KB Output is correct
15 Correct 55 ms 13008 KB Output is correct
16 Correct 54 ms 13136 KB Output is correct
17 Correct 54 ms 12872 KB Output is correct
18 Correct 53 ms 12880 KB Output is correct
19 Correct 52 ms 12764 KB Output is correct
20 Correct 53 ms 12736 KB Output is correct
21 Correct 54 ms 12740 KB Output is correct
22 Correct 56 ms 12608 KB Output is correct
23 Correct 43 ms 11936 KB Output is correct
24 Correct 48 ms 11944 KB Output is correct
25 Correct 46 ms 12212 KB Output is correct
26 Correct 47 ms 12144 KB Output is correct
27 Correct 52 ms 12608 KB Output is correct
28 Correct 52 ms 12840 KB Output is correct
29 Correct 53 ms 12992 KB Output is correct
30 Correct 55 ms 13004 KB Output is correct
31 Correct 51 ms 11848 KB Output is correct
32 Correct 45 ms 11848 KB Output is correct
33 Correct 46 ms 12468 KB Output is correct
34 Correct 47 ms 12332 KB Output is correct
35 Correct 59 ms 12828 KB Output is correct
36 Correct 52 ms 12692 KB Output is correct
37 Correct 50 ms 12480 KB Output is correct
38 Correct 51 ms 12608 KB Output is correct
39 Correct 52 ms 12648 KB Output is correct
40 Correct 50 ms 12704 KB Output is correct
41 Correct 53 ms 12872 KB Output is correct
42 Correct 59 ms 12912 KB Output is correct
43 Correct 57 ms 12828 KB Output is correct
44 Correct 62 ms 12908 KB Output is correct
45 Correct 60 ms 12736 KB Output is correct
46 Correct 54 ms 12884 KB Output is correct
47 Correct 55 ms 12360 KB Output is correct
48 Correct 48 ms 12488 KB Output is correct
49 Correct 47 ms 12416 KB Output is correct
50 Correct 50 ms 12672 KB Output is correct
51 Correct 45 ms 12232 KB Output is correct
52 Correct 47 ms 12224 KB Output is correct
53 Correct 45 ms 12360 KB Output is correct
54 Correct 48 ms 12364 KB Output is correct
55 Correct 46 ms 12288 KB Output is correct
56 Correct 45 ms 12352 KB Output is correct
57 Correct 45 ms 11988 KB Output is correct
58 Correct 46 ms 11852 KB Output is correct
59 Correct 47 ms 12224 KB Output is correct
60 Correct 46 ms 12108 KB Output is correct