Submission #780130

# Submission time Handle Problem Language Result Execution time Memory
780130 2023-07-12T06:49:02 Z ymm Stray Cat (JOI20_stray) C++17
100 / 100
45 ms 16528 KB
#include "Anthony.h"
#include <bits/stdc++.h>
#define Loop(x, l, r) for (ll x = (l); x < (r); ++x)
typedef long long ll;
using namespace std;

namespace {

	const int N = 20'010;
	vector<int> A[N];
	int dis[N];
	void bfs() {
		memset(dis, -1, sizeof(dis));
		vector<int> q = {0};
		dis[0] = 0;
		Loop (i,0,q.size()) {
			int v = q[i];
			for (int u : A[v]) {
				if (dis[u] == -1) {
					dis[u] = dis[v]+1;
					q.push_back(u);
				}
			}
		}
	}
	int height[N];
	int val[N];
	const int pat[] = {0, 0, 1, 0, 1, 1};
	const int pats = sizeof(pat)/sizeof(*pat);
	void dfs(int v, int p, int x, int h) {
		height[v] = h;
		val[v] = pat[x%pats];
		for (int u : A[v]) {
			if (u == p)
				continue;
			if (A[v].size() == 2)
				dfs(u, v, x+1, h+1);
			else
				dfs(u, v, val[v]==0? 2: 0, h+1);
		}
	}

}  // namespace

std::vector<int> Mark(int N, int M, int a, int b,
                      std::vector<int> U, std::vector<int> V) {
	Loop (i,0,M) {
		int v = V[i], u = U[i];
		A[v].push_back(u);
		A[u].push_back(v);
	}
	vector<int> ans(M);
	if (a == 2) {
		dfs(0, -1, 0, 0);
		Loop (i,0,M) {
			int v = V[i], u = U[i];
			if (height[v] > height[u])
				swap(v, u);
			ans[i] = val[u];
		}
	} else {
		bfs();
		Loop (i,0,M) {
			int v = V[i], u = U[i];
			ans[i] = min(dis[v], dis[u]) % 3;
		}
	}
	return ans;
}
#include "Catherine.h"
#include <bits/stdc++.h>
#define Loop(x, l, r) for (ll x = (l); x < (r); ++x)
typedef long long ll;
using namespace std;

namespace {

	int (*move_ptr)(vector<int>);
	int lst = -1;

	int move3(vector<int> y) {
		if (y[0] && y[1])
			return 0;
		if (y[1] && y[2])
			return 1;
		if (y[2] && y[0])
			return 2;
		return !!y[1] + 2*!!y[2];
	}

	int move_up(vector<int> y) {
		if (y[0] + y[1] == 1)
			return !!y[1];
		if (y[0] + (lst == 0) == 1)
			return y[0]? 0: -1;
		else
			return y[1]? 1: -1;
	}

	const int pat[] = {0, 0, 1, 0, 1, 1};
	const int pats = sizeof(pat)/sizeof(*pat);
	vector<int> cur_pat;

	bool test() {
		vector<int> p(pat, pat+pats), q(cur_pat);
		Loop (_,0,pats) {
			int x = p.back();
			p.pop_back();
			if (p == q)
				return 0;
			p.insert(p.begin(), x);
		}
		return 1;
	}

	int move_test(vector<int> y) {
		if (y[0] + y[1] + (lst != -1) != 2)
			return (move_ptr = move_up)(y);
		if (cur_pat.size() == 0) {
			if (y[0] && y[1]) {
				cur_pat = {0, 1};
				return 1;
			}
			if (y[0]) {
				cur_pat = {0, 0};
				return 0;
			} else {
				cur_pat = {1, 1};
				return 1;
			}
		}
		cur_pat.push_back(!!y[1]);
		if (cur_pat.size() == 5) {
			move_ptr = move_up;
			if (test())
				return move_up(y);
			else
				return -1;
		}
		return !!y[1];
	}

}  // namespace

void Init(int A, int B) {
	move_ptr = A == 2? move_test: move3;
}

int Move(std::vector<int> y) {
	int x = move_ptr(y);
	lst = x;
	return x;
}

Compilation message

Anthony.cpp: In function 'void {anonymous}::bfs()':
Anthony.cpp:3:42: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    3 | #define Loop(x, l, r) for (ll x = (l); x < (r); ++x)
      |                                          ^
Anthony.cpp:16:3: note: in expansion of macro 'Loop'
   16 |   Loop (i,0,q.size()) {
      |   ^~~~
# Verdict Execution time Memory Grader output
1 Correct 28 ms 15424 KB Output is correct
2 Correct 1 ms 1172 KB Output is correct
3 Correct 24 ms 14792 KB Output is correct
4 Correct 34 ms 16512 KB Output is correct
5 Correct 34 ms 16528 KB Output is correct
6 Correct 39 ms 15212 KB Output is correct
7 Correct 28 ms 15268 KB Output is correct
8 Correct 34 ms 15980 KB Output is correct
9 Correct 40 ms 15960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 15424 KB Output is correct
2 Correct 1 ms 1172 KB Output is correct
3 Correct 24 ms 14792 KB Output is correct
4 Correct 34 ms 16512 KB Output is correct
5 Correct 34 ms 16528 KB Output is correct
6 Correct 39 ms 15212 KB Output is correct
7 Correct 28 ms 15268 KB Output is correct
8 Correct 34 ms 15980 KB Output is correct
9 Correct 40 ms 15960 KB Output is correct
10 Correct 26 ms 13184 KB Output is correct
11 Correct 25 ms 13336 KB Output is correct
12 Correct 25 ms 13368 KB Output is correct
13 Correct 25 ms 13332 KB Output is correct
14 Correct 30 ms 13684 KB Output is correct
15 Correct 28 ms 13940 KB Output is correct
16 Correct 30 ms 16112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 13040 KB Output is correct
2 Correct 1 ms 1148 KB Output is correct
3 Correct 26 ms 12564 KB Output is correct
4 Correct 43 ms 14412 KB Output is correct
5 Correct 44 ms 14404 KB Output is correct
6 Correct 25 ms 13016 KB Output is correct
7 Correct 25 ms 13048 KB Output is correct
8 Correct 31 ms 13640 KB Output is correct
9 Correct 37 ms 13688 KB Output is correct
10 Correct 36 ms 13472 KB Output is correct
11 Correct 30 ms 13480 KB Output is correct
12 Correct 27 ms 13528 KB Output is correct
13 Correct 30 ms 13492 KB Output is correct
14 Correct 30 ms 13716 KB Output is correct
15 Correct 40 ms 13732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 13040 KB Output is correct
2 Correct 1 ms 1148 KB Output is correct
3 Correct 26 ms 12564 KB Output is correct
4 Correct 43 ms 14412 KB Output is correct
5 Correct 44 ms 14404 KB Output is correct
6 Correct 25 ms 13016 KB Output is correct
7 Correct 25 ms 13048 KB Output is correct
8 Correct 31 ms 13640 KB Output is correct
9 Correct 37 ms 13688 KB Output is correct
10 Correct 36 ms 13472 KB Output is correct
11 Correct 30 ms 13480 KB Output is correct
12 Correct 27 ms 13528 KB Output is correct
13 Correct 30 ms 13492 KB Output is correct
14 Correct 30 ms 13716 KB Output is correct
15 Correct 40 ms 13732 KB Output is correct
16 Correct 28 ms 11476 KB Output is correct
17 Correct 27 ms 11564 KB Output is correct
18 Correct 29 ms 11436 KB Output is correct
19 Correct 24 ms 11468 KB Output is correct
20 Correct 31 ms 12040 KB Output is correct
21 Correct 31 ms 11844 KB Output is correct
22 Correct 29 ms 13900 KB Output is correct
23 Correct 25 ms 11552 KB Output is correct
24 Correct 25 ms 11460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1284 KB Output is correct
2 Correct 1 ms 1032 KB Output is correct
3 Correct 2 ms 1284 KB Output is correct
4 Correct 2 ms 1292 KB Output is correct
5 Correct 2 ms 1280 KB Output is correct
6 Correct 2 ms 1356 KB Output is correct
7 Correct 2 ms 1424 KB Output is correct
8 Correct 2 ms 1416 KB Output is correct
9 Correct 2 ms 1292 KB Output is correct
10 Correct 2 ms 1340 KB Output is correct
11 Correct 2 ms 1284 KB Output is correct
12 Correct 2 ms 1292 KB Output is correct
13 Correct 2 ms 1324 KB Output is correct
14 Correct 3 ms 1308 KB Output is correct
15 Correct 2 ms 1288 KB Output is correct
16 Correct 2 ms 1288 KB Output is correct
17 Correct 2 ms 1348 KB Output is correct
18 Correct 2 ms 1288 KB Output is correct
19 Correct 2 ms 1288 KB Output is correct
20 Correct 2 ms 1352 KB Output is correct
21 Correct 2 ms 1292 KB Output is correct
22 Correct 2 ms 1288 KB Output is correct
23 Correct 2 ms 1316 KB Output is correct
24 Correct 2 ms 1288 KB Output is correct
25 Correct 2 ms 1348 KB Output is correct
26 Correct 2 ms 1288 KB Output is correct
27 Correct 2 ms 1296 KB Output is correct
28 Correct 2 ms 1296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 11120 KB Output is correct
2 Correct 34 ms 12292 KB Output is correct
3 Correct 1 ms 1004 KB Output is correct
4 Correct 20 ms 11344 KB Output is correct
5 Correct 38 ms 14312 KB Output is correct
6 Correct 36 ms 14352 KB Output is correct
7 Correct 37 ms 13452 KB Output is correct
8 Correct 26 ms 13500 KB Output is correct
9 Correct 34 ms 14292 KB Output is correct
10 Correct 43 ms 14408 KB Output is correct
11 Correct 45 ms 14376 KB Output is correct
12 Correct 32 ms 14340 KB Output is correct
13 Correct 42 ms 14416 KB Output is correct
14 Correct 31 ms 14348 KB Output is correct
15 Correct 36 ms 14252 KB Output is correct
16 Correct 30 ms 14416 KB Output is correct
17 Correct 33 ms 14128 KB Output is correct
18 Correct 33 ms 13988 KB Output is correct
19 Correct 31 ms 14128 KB Output is correct
20 Correct 30 ms 14140 KB Output is correct
21 Correct 28 ms 14144 KB Output is correct
22 Correct 33 ms 14020 KB Output is correct
23 Correct 26 ms 11584 KB Output is correct
24 Correct 27 ms 11556 KB Output is correct
25 Correct 25 ms 12092 KB Output is correct
26 Correct 25 ms 12140 KB Output is correct
27 Correct 27 ms 12988 KB Output is correct
28 Correct 30 ms 12984 KB Output is correct
29 Correct 33 ms 12988 KB Output is correct
30 Correct 36 ms 12988 KB Output is correct
31 Correct 37 ms 11456 KB Output is correct
32 Correct 28 ms 11568 KB Output is correct
33 Correct 28 ms 12004 KB Output is correct
34 Correct 28 ms 11980 KB Output is correct
35 Correct 30 ms 12764 KB Output is correct
36 Correct 26 ms 12788 KB Output is correct
37 Correct 27 ms 12724 KB Output is correct
38 Correct 30 ms 12728 KB Output is correct
39 Correct 28 ms 12720 KB Output is correct
40 Correct 26 ms 12724 KB Output is correct
41 Correct 33 ms 13464 KB Output is correct
42 Correct 34 ms 13460 KB Output is correct
43 Correct 28 ms 13368 KB Output is correct
44 Correct 28 ms 13372 KB Output is correct
45 Correct 30 ms 13492 KB Output is correct
46 Correct 31 ms 13564 KB Output is correct
47 Correct 31 ms 12644 KB Output is correct
48 Correct 30 ms 12528 KB Output is correct
49 Correct 36 ms 12416 KB Output is correct
50 Correct 26 ms 12660 KB Output is correct
51 Correct 25 ms 11744 KB Output is correct
52 Correct 30 ms 11868 KB Output is correct
53 Correct 27 ms 11904 KB Output is correct
54 Correct 28 ms 11736 KB Output is correct
55 Correct 34 ms 11784 KB Output is correct
56 Correct 27 ms 11788 KB Output is correct
57 Correct 34 ms 11772 KB Output is correct
58 Correct 25 ms 11788 KB Output is correct
59 Correct 24 ms 11968 KB Output is correct
60 Correct 25 ms 11960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 11080 KB Output is correct
2 Correct 38 ms 12696 KB Output is correct
3 Correct 1 ms 1028 KB Output is correct
4 Correct 25 ms 11416 KB Output is correct
5 Correct 33 ms 14388 KB Output is correct
6 Correct 31 ms 14244 KB Output is correct
7 Correct 31 ms 13484 KB Output is correct
8 Correct 30 ms 13500 KB Output is correct
9 Correct 32 ms 14384 KB Output is correct
10 Correct 30 ms 14392 KB Output is correct
11 Correct 34 ms 14360 KB Output is correct
12 Correct 33 ms 14380 KB Output is correct
13 Correct 31 ms 14360 KB Output is correct
14 Correct 42 ms 14352 KB Output is correct
15 Correct 41 ms 14228 KB Output is correct
16 Correct 42 ms 14392 KB Output is correct
17 Correct 27 ms 14016 KB Output is correct
18 Correct 28 ms 14068 KB Output is correct
19 Correct 34 ms 13924 KB Output is correct
20 Correct 34 ms 14096 KB Output is correct
21 Correct 28 ms 14016 KB Output is correct
22 Correct 28 ms 14064 KB Output is correct
23 Correct 27 ms 11504 KB Output is correct
24 Correct 25 ms 11532 KB Output is correct
25 Correct 30 ms 12032 KB Output is correct
26 Correct 28 ms 11892 KB Output is correct
27 Correct 27 ms 12936 KB Output is correct
28 Correct 28 ms 12988 KB Output is correct
29 Correct 33 ms 12988 KB Output is correct
30 Correct 27 ms 12984 KB Output is correct
31 Correct 29 ms 11528 KB Output is correct
32 Correct 26 ms 11524 KB Output is correct
33 Correct 25 ms 12120 KB Output is correct
34 Correct 26 ms 12116 KB Output is correct
35 Correct 26 ms 12772 KB Output is correct
36 Correct 27 ms 12788 KB Output is correct
37 Correct 37 ms 12684 KB Output is correct
38 Correct 28 ms 12736 KB Output is correct
39 Correct 27 ms 12740 KB Output is correct
40 Correct 27 ms 12796 KB Output is correct
41 Correct 37 ms 13452 KB Output is correct
42 Correct 39 ms 13296 KB Output is correct
43 Correct 28 ms 13456 KB Output is correct
44 Correct 38 ms 13512 KB Output is correct
45 Correct 27 ms 13552 KB Output is correct
46 Correct 38 ms 13416 KB Output is correct
47 Correct 26 ms 12536 KB Output is correct
48 Correct 27 ms 12592 KB Output is correct
49 Correct 26 ms 12604 KB Output is correct
50 Correct 32 ms 12552 KB Output is correct
51 Correct 30 ms 11832 KB Output is correct
52 Correct 25 ms 11816 KB Output is correct
53 Correct 31 ms 11912 KB Output is correct
54 Correct 28 ms 11708 KB Output is correct
55 Correct 34 ms 11852 KB Output is correct
56 Correct 25 ms 11844 KB Output is correct
57 Correct 25 ms 11760 KB Output is correct
58 Correct 24 ms 11740 KB Output is correct
59 Correct 31 ms 11952 KB Output is correct
60 Correct 28 ms 11916 KB Output is correct