Submission #446227

# Submission time Handle Problem Language Result Execution time Memory
446227 2021-07-21T09:49:39 Z ics0503 Stray Cat (JOI20_stray) C++17
100 / 100
62 ms 16552 KB
#include "Anthony.h"
#include <vector>
#include<algorithm>
#include<deque>
using namespace std;

// pattern: 110100110100

vector<pair<int,int>>edge[21212];
vector<int> X;
int st;
int pattern[6] = { 1,1,0,1,0,0 };
void dfs(int w, int bef,int befState) {
	if (bef == -1) {
		for (auto ne : edge[w]) {
			int nxt = ne.first;
			X[ne.second] = pattern[0];
			dfs(nxt, w, 0);
		}
		return;
	}
	if (edge[w].size() == 2) {
		for (auto ne : edge[w]) {
			int nxt = ne.first;
			if (nxt == bef)continue;
			int state = (befState + 1) % 6;
			X[ne.second] = pattern[state];
			dfs(nxt, w, state);
		}
	}
	else {
		for (auto ne : edge[w]) {
			int nxt = ne.first;
			if (nxt == bef)continue;
			int state = 0;
			if (pattern[befState] == 0) state = 0;
			else state = 2;
			X[ne.second] = pattern[state];
			dfs(nxt, w, state);
		}
	}
}

int dist[21212];
void bfs(int n) {
	deque<int>Q;
	Q.push_back(0);
	int i, j;
	for (i = 0; i < n; i++) dist[i] = n + 1;
	dist[0] = 0;
	while (!Q.empty()) {
		int now = Q.front(); Q.pop_front();
		for (auto ne : edge[now]) {
			int nxt = ne.first;
			if (dist[nxt] > dist[now] + 1) {
				dist[nxt] = dist[now] + 1;
				Q.push_back(nxt);
			}
		}
	}
}

vector<int> Mark(int n, int m, int a, int b, vector<int> U, vector<int> V) {
	int i, j;
	for (i = 0; i < m; i++)X.push_back(0);
	for (i = 0; i < m; i++) {
		int s = U[i], e = V[i];
		edge[s].push_back({ e,i }); edge[e].push_back({ s,i });
	}
	if (a == 2) {
		dfs(0, -1, 0);
	}
	else {
		bfs(n);
		for (i = 0; i < m; i++) {
			X[i] = min(dist[U[i]], dist[V[i]]) % 3;
		}
	}
	return X;
}
#include "Catherine.h"
#include <vector>
#include<deque>
using namespace std;
int a, b;

deque<int>state;
int flag = 0, befSelection;
void Init(int A, int B) {
	a = A, b = B;
	state.clear();
	befSelection = -1;
	flag = 0;
}
/*
11010
10100
01001
10011
00110
01101
*/
int turnNum = 0;
int a2move(vector<int>&y) {
	if (flag == 2) {
		if (turnNum > 0) {
			turnNum--;
			return state[turnNum + 1];
		}
		else {
			flag = 1;
			befSelection = state[1];
		}
	}
	if (flag == 1) {
		if (y[0] + y[1] == 1) {
			if (y[0])return befSelection = 0;
			if (y[1])return befSelection = 1;
		}
		if (befSelection == 0)return befSelection = 1;
		return befSelection = 0;
	}
	if (state.empty()) {
		if (y[0] + y[1] >= 3) {
			if (y[0] == 1) {
				flag = 1;
				return befSelection = 0;
			}
			else {
				flag = 1;
				return befSelection = 1;
			}
		}
		if (y[0] && y[1]) { state.push_back(1); state.push_back(0); return befSelection = 0; }
		else {
			if (y[0] == 0 && y[1] == 1) {
				flag = 1;
				return befSelection = 1;
			}
			if (y[0] == 1 && y[1] == 0) {
				flag = 1;
				return befSelection = 0;
			}
			if (y[0]) {
				if (y[0] >= 2)state.push_back(0);
				state.push_back(0);
				return befSelection = 0;
			}
			else {
				if (y[1] >= 2)state.push_back(1);
				state.push_back(1);
				return befSelection = 1;
			}
		}
	}
	else {
		if (y[0] + y[1] == 0) {
			flag = 2;
			turnNum = state.size() - 1;
			turnNum--;
			return -1;
		}
		if (y[0] + y[1] >= 2) {
			flag = 1;
			if (y[0] == 0 && befSelection == 0) {
				flag = 2;
				turnNum = state.size()-1;
				turnNum--;
				return -1;
			}
			if (y[1] == 0 && befSelection == 1) {
				flag = 2;
				turnNum = state.size() - 1;
				turnNum--;
				return -1;
			}
			if (befSelection == 0)return befSelection = 1;
			else return befSelection = 0;
		}
		if (flag == 0 && state.size() == 4) {
			if (y[0]) state.push_back(0);
			if (y[1]) state.push_back(1);
			int allST[6][5] = {
					{1,1,0,1,0},
					{1,0,1,0,0},
					{0,1,0,0,1},
					{1,0,0,1,1},
					{0,0,1,1,0},
					{0,1,1,0,1},
			};
			int i, j;
			for (i = 0; i < 6; i++) {
				int qq = 1;
				for (j = 0; j < 5; j++) {
					if (allST[i][4-j] != state[j])qq = 0;
				}
				if (qq) {
					flag = 1;
					return befSelection = state[4];
				}
			}
			flag = 2;
			turnNum = 3;
			turnNum--;
			return -1;
		}
		if (y[0]) {
			state.push_back(0);
			return befSelection = 0;
		}
		else {
			state.push_back(1);
			return befSelection = 1;
		}
	}
}

int a3move(vector<int>y) {
	if(befSelection!=-1)y[befSelection]++;
	if (y[0] && y[1])return befSelection = 0;
	if (y[1] && y[2])return befSelection = 1;
	if (y[2] && y[0])return befSelection = 2;
	if (y[0])return befSelection = 0;
	if (y[1])return befSelection = 1;
	if (y[2])return befSelection = 2;
}

int Move(vector<int> y) {
	if (a == 2) return a2move(y);
	else return a3move(y);
}

Compilation message

Anthony.cpp: In function 'void bfs(int)':
Anthony.cpp:48:9: warning: unused variable 'j' [-Wunused-variable]
   48 |  int i, j;
      |         ^
Anthony.cpp: In function 'std::vector<int> Mark(int, int, int, int, std::vector<int>, std::vector<int>)':
Anthony.cpp:64:9: warning: unused variable 'j' [-Wunused-variable]
   64 |  int i, j;
      |         ^

Catherine.cpp: In function 'int a3move(std::vector<int>)':
Catherine.cpp:146:1: warning: control reaches end of non-void function [-Wreturn-type]
  146 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 46 ms 15480 KB Output is correct
2 Correct 1 ms 996 KB Output is correct
3 Correct 36 ms 14864 KB Output is correct
4 Correct 55 ms 16512 KB Output is correct
5 Correct 56 ms 16552 KB Output is correct
6 Correct 43 ms 15292 KB Output is correct
7 Correct 44 ms 15240 KB Output is correct
8 Correct 52 ms 15872 KB Output is correct
9 Correct 52 ms 16044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 15480 KB Output is correct
2 Correct 1 ms 996 KB Output is correct
3 Correct 36 ms 14864 KB Output is correct
4 Correct 55 ms 16512 KB Output is correct
5 Correct 56 ms 16552 KB Output is correct
6 Correct 43 ms 15292 KB Output is correct
7 Correct 44 ms 15240 KB Output is correct
8 Correct 52 ms 15872 KB Output is correct
9 Correct 52 ms 16044 KB Output is correct
10 Correct 41 ms 13440 KB Output is correct
11 Correct 45 ms 13336 KB Output is correct
12 Correct 39 ms 13352 KB Output is correct
13 Correct 43 ms 13388 KB Output is correct
14 Correct 42 ms 13688 KB Output is correct
15 Correct 49 ms 13996 KB Output is correct
16 Correct 49 ms 16024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 12988 KB Output is correct
2 Correct 1 ms 1004 KB Output is correct
3 Correct 34 ms 12652 KB Output is correct
4 Correct 62 ms 14276 KB Output is correct
5 Correct 56 ms 14348 KB Output is correct
6 Correct 41 ms 12984 KB Output is correct
7 Correct 42 ms 13116 KB Output is correct
8 Correct 49 ms 13756 KB Output is correct
9 Correct 49 ms 13660 KB Output is correct
10 Correct 49 ms 13444 KB Output is correct
11 Correct 46 ms 13456 KB Output is correct
12 Correct 46 ms 13448 KB Output is correct
13 Correct 46 ms 13408 KB Output is correct
14 Correct 49 ms 13652 KB Output is correct
15 Correct 49 ms 13740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 12988 KB Output is correct
2 Correct 1 ms 1004 KB Output is correct
3 Correct 34 ms 12652 KB Output is correct
4 Correct 62 ms 14276 KB Output is correct
5 Correct 56 ms 14348 KB Output is correct
6 Correct 41 ms 12984 KB Output is correct
7 Correct 42 ms 13116 KB Output is correct
8 Correct 49 ms 13756 KB Output is correct
9 Correct 49 ms 13660 KB Output is correct
10 Correct 49 ms 13444 KB Output is correct
11 Correct 46 ms 13456 KB Output is correct
12 Correct 46 ms 13448 KB Output is correct
13 Correct 46 ms 13408 KB Output is correct
14 Correct 49 ms 13652 KB Output is correct
15 Correct 49 ms 13740 KB Output is correct
16 Correct 34 ms 11472 KB Output is correct
17 Correct 34 ms 11592 KB Output is correct
18 Correct 40 ms 11448 KB Output is correct
19 Correct 43 ms 11568 KB Output is correct
20 Correct 44 ms 12012 KB Output is correct
21 Correct 41 ms 11820 KB Output is correct
22 Correct 48 ms 13928 KB Output is correct
23 Correct 38 ms 11672 KB Output is correct
24 Correct 39 ms 11524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1256 KB Output is correct
2 Correct 1 ms 996 KB Output is correct
3 Correct 2 ms 1256 KB Output is correct
4 Correct 2 ms 1388 KB Output is correct
5 Correct 2 ms 1256 KB Output is correct
6 Correct 2 ms 1268 KB Output is correct
7 Correct 2 ms 1252 KB Output is correct
8 Correct 2 ms 1384 KB Output is correct
9 Correct 2 ms 1372 KB Output is correct
10 Correct 2 ms 1296 KB Output is correct
11 Correct 2 ms 1256 KB Output is correct
12 Correct 2 ms 1256 KB Output is correct
13 Correct 2 ms 1264 KB Output is correct
14 Correct 2 ms 1256 KB Output is correct
15 Correct 2 ms 1264 KB Output is correct
16 Correct 2 ms 1256 KB Output is correct
17 Correct 2 ms 1256 KB Output is correct
18 Correct 2 ms 1256 KB Output is correct
19 Correct 2 ms 1256 KB Output is correct
20 Correct 2 ms 1264 KB Output is correct
21 Correct 2 ms 1256 KB Output is correct
22 Correct 2 ms 1256 KB Output is correct
23 Correct 2 ms 1256 KB Output is correct
24 Correct 2 ms 1268 KB Output is correct
25 Correct 2 ms 1256 KB Output is correct
26 Correct 2 ms 1256 KB Output is correct
27 Correct 2 ms 1256 KB Output is correct
28 Correct 2 ms 1256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 11220 KB Output is correct
2 Correct 42 ms 12192 KB Output is correct
3 Correct 1 ms 1072 KB Output is correct
4 Correct 33 ms 11260 KB Output is correct
5 Correct 48 ms 14068 KB Output is correct
6 Correct 51 ms 13884 KB Output is correct
7 Correct 41 ms 13040 KB Output is correct
8 Correct 40 ms 13096 KB Output is correct
9 Correct 49 ms 14020 KB Output is correct
10 Correct 49 ms 13944 KB Output is correct
11 Correct 51 ms 13968 KB Output is correct
12 Correct 47 ms 13916 KB Output is correct
13 Correct 52 ms 13932 KB Output is correct
14 Correct 51 ms 13892 KB Output is correct
15 Correct 50 ms 13924 KB Output is correct
16 Correct 49 ms 13916 KB Output is correct
17 Correct 48 ms 13812 KB Output is correct
18 Correct 48 ms 13712 KB Output is correct
19 Correct 46 ms 13640 KB Output is correct
20 Correct 45 ms 13696 KB Output is correct
21 Correct 48 ms 13748 KB Output is correct
22 Correct 44 ms 13600 KB Output is correct
23 Correct 38 ms 11544 KB Output is correct
24 Correct 38 ms 11668 KB Output is correct
25 Correct 39 ms 11996 KB Output is correct
26 Correct 39 ms 11876 KB Output is correct
27 Correct 44 ms 12720 KB Output is correct
28 Correct 47 ms 12684 KB Output is correct
29 Correct 44 ms 12736 KB Output is correct
30 Correct 47 ms 12824 KB Output is correct
31 Correct 38 ms 11592 KB Output is correct
32 Correct 38 ms 11652 KB Output is correct
33 Correct 39 ms 11916 KB Output is correct
34 Correct 39 ms 11912 KB Output is correct
35 Correct 45 ms 12512 KB Output is correct
36 Correct 44 ms 12572 KB Output is correct
37 Correct 43 ms 12524 KB Output is correct
38 Correct 46 ms 12708 KB Output is correct
39 Correct 43 ms 12520 KB Output is correct
40 Correct 47 ms 12556 KB Output is correct
41 Correct 47 ms 13108 KB Output is correct
42 Correct 56 ms 13212 KB Output is correct
43 Correct 46 ms 13192 KB Output is correct
44 Correct 50 ms 13208 KB Output is correct
45 Correct 47 ms 13256 KB Output is correct
46 Correct 45 ms 13208 KB Output is correct
47 Correct 41 ms 12532 KB Output is correct
48 Correct 43 ms 12552 KB Output is correct
49 Correct 41 ms 12340 KB Output is correct
50 Correct 42 ms 12512 KB Output is correct
51 Correct 39 ms 11768 KB Output is correct
52 Correct 39 ms 11816 KB Output is correct
53 Correct 39 ms 11756 KB Output is correct
54 Correct 39 ms 11804 KB Output is correct
55 Correct 41 ms 11752 KB Output is correct
56 Correct 39 ms 11756 KB Output is correct
57 Correct 39 ms 11652 KB Output is correct
58 Correct 38 ms 11660 KB Output is correct
59 Correct 39 ms 11760 KB Output is correct
60 Correct 42 ms 11720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 11224 KB Output is correct
2 Correct 45 ms 12584 KB Output is correct
3 Correct 1 ms 1000 KB Output is correct
4 Correct 37 ms 11460 KB Output is correct
5 Correct 54 ms 13872 KB Output is correct
6 Correct 51 ms 13864 KB Output is correct
7 Correct 44 ms 13104 KB Output is correct
8 Correct 41 ms 13076 KB Output is correct
9 Correct 50 ms 13892 KB Output is correct
10 Correct 55 ms 13928 KB Output is correct
11 Correct 57 ms 14020 KB Output is correct
12 Correct 52 ms 13928 KB Output is correct
13 Correct 49 ms 13888 KB Output is correct
14 Correct 49 ms 13936 KB Output is correct
15 Correct 48 ms 13896 KB Output is correct
16 Correct 53 ms 13916 KB Output is correct
17 Correct 51 ms 13656 KB Output is correct
18 Correct 47 ms 13708 KB Output is correct
19 Correct 47 ms 13712 KB Output is correct
20 Correct 45 ms 13636 KB Output is correct
21 Correct 45 ms 13636 KB Output is correct
22 Correct 45 ms 13612 KB Output is correct
23 Correct 40 ms 11596 KB Output is correct
24 Correct 39 ms 11480 KB Output is correct
25 Correct 39 ms 11992 KB Output is correct
26 Correct 41 ms 11908 KB Output is correct
27 Correct 46 ms 12808 KB Output is correct
28 Correct 44 ms 12692 KB Output is correct
29 Correct 50 ms 12692 KB Output is correct
30 Correct 45 ms 12708 KB Output is correct
31 Correct 37 ms 11520 KB Output is correct
32 Correct 38 ms 11648 KB Output is correct
33 Correct 40 ms 11888 KB Output is correct
34 Correct 41 ms 12096 KB Output is correct
35 Correct 43 ms 12608 KB Output is correct
36 Correct 49 ms 12620 KB Output is correct
37 Correct 45 ms 12496 KB Output is correct
38 Correct 43 ms 12560 KB Output is correct
39 Correct 44 ms 12656 KB Output is correct
40 Correct 47 ms 12604 KB Output is correct
41 Correct 48 ms 13112 KB Output is correct
42 Correct 47 ms 13132 KB Output is correct
43 Correct 44 ms 13248 KB Output is correct
44 Correct 46 ms 13212 KB Output is correct
45 Correct 46 ms 13184 KB Output is correct
46 Correct 48 ms 13200 KB Output is correct
47 Correct 50 ms 12392 KB Output is correct
48 Correct 49 ms 12484 KB Output is correct
49 Correct 44 ms 12428 KB Output is correct
50 Correct 43 ms 12396 KB Output is correct
51 Correct 40 ms 11840 KB Output is correct
52 Correct 40 ms 11704 KB Output is correct
53 Correct 38 ms 11760 KB Output is correct
54 Correct 40 ms 11664 KB Output is correct
55 Correct 41 ms 11760 KB Output is correct
56 Correct 40 ms 11732 KB Output is correct
57 Correct 38 ms 11632 KB Output is correct
58 Correct 39 ms 11672 KB Output is correct
59 Correct 39 ms 11824 KB Output is correct
60 Correct 39 ms 11736 KB Output is correct