Submission #758984

# Submission time Handle Problem Language Result Execution time Memory
758984 2023-06-15T16:20:13 Z siewjh Stray Cat (JOI20_stray) C++17
100 / 100
48 ms 16484 KB
#include "Anthony.h"
#include <bits/stdc++.h>
using namespace std;

namespace {
	const int MAXN = 20005;
	vector<pair<int, int>> adj[MAXN];
	vector<int> marking;
	int cyc[6] = {0, 0, 1, 0, 1, 1};
	
	void dfs(int x, int par, int cind){
		if (par != -1 && adj[x].size() >= 3){
			int prv = cyc[(cind + 5) % 6];
			if (prv == 0) cind = 5;
			else cind = 0;
		}
		for (auto nxt : adj[x]){
			int nn = nxt.first, edge = nxt.second;
			if (nn == par) continue;
			marking[edge] = cyc[cind];
			dfs(nn, x, (cind + 1) % 6);
		}
	}
}

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});
	}
	marking.resize(M);
	if (A >= 3){
		vector<int> dist(N, -1);
		dist[0] = 0;
		queue<int> q;
		q.push(0);
		while (!q.empty()){
			int x = q.front(); q.pop();
			for (auto nxt : adj[x]){
				int nn = nxt.first, edge = nxt.second;
				if (dist[nn] != -1){
					if (dist[nn] == dist[x] - 1) continue; // already marked
					else marking[edge] = dist[x] % 3;
				}
				else{
					marking[edge] = dist[x] % 3;
					dist[nn] = dist[x] + 1;
					q.push(nn);
				}
			}
		}
	}
	else{
		dfs(0, -1, 0);
	}
	return marking;
}
#include "Catherine.h"
#include <bits/stdc++.h>
using namespace std;

namespace {
	int A, B;
	int steps = 0; // 0 to 3 -> first steps, -1 -> straight up
	int prv = -1; // previous edge
	int seq = 0; // 5 digit sequence
	set<int> ok;
}

void Init(int A, int B) {
	::A = A;
	::B = B;
	// up: 11010, 10100, 01001, 10011, 00110, 01101
	ok = {26, 20, 9, 19, 6, 13};
}

int Move(vector<int> y){
	if (A >= 3){
		int types = 0;
		for (int i = 0; i < 3; i++)
			if (y[i])
				types++;
		if (types == 1){
			for (int i = 0; i < 3; i++)
				if (y[i])
					return i;
		}
		else{ // types == 2
			for (int i = 0; i < 3; i++)
				if (!y[i])
					return (i + 1) % 3;
		}
		return -1; // will never happen
	}
	else{
		if (y[0] == 0 && y[1] == 0){ // dead end
			steps = -1; // prv unchanged
			return -1;
		}
		else if (y[0] + y[1] + (prv != -1) >= 3){ // deg >= 3
			steps = -1;
			int y0 = y[0] + (prv == 0), y1 = y[1] + (prv == 1);
			if (y0 == 1){
				int ret = ((prv == 0) ? -1 : 0);
				prv = 0;
				return ret;
			}
			else{
				int ret = ((prv == 1) ? -1 : 1);
				prv = 1;
				return ret;
			}
		}
		else if (steps == -1){ // go up
			if (y[0]) return prv = 0;
			else return prv = 1;
		}
		else if (steps == 0){
			int go, other;
			if (y[0]){
				go = 0;
				if (y[1]) other = 1; else other = 0;
			}
			else go = other = 1;
			steps++;
			prv = go;
			seq = (other << 1) + go;
			return go;
		}
		else if (steps < 3){
			int go;
			if (y[0]) go = 0; else go = 1;
			steps++;
			prv = go;
			seq = (seq << 1) + go;
			return go;
		}
		else{ // see if we are going correct direction
			int nxt;
			if (y[0]) nxt = 0; else nxt = 1;
			seq = (seq << 1) + nxt;
			steps = -1;
			if (ok.count(seq)){ // continue
				return prv = nxt;
			}
			else return -1;
		}
	}
}

Compilation message

Catherine.cpp: In function 'int Move(std::vector<int>)':
Catherine.cpp:45:32: warning: unused variable 'y1' [-Wunused-variable]
   45 |    int y0 = y[0] + (prv == 0), y1 = y[1] + (prv == 1);
      |                                ^~
# Verdict Execution time Memory Grader output
1 Correct 30 ms 15436 KB Output is correct
2 Correct 1 ms 1032 KB Output is correct
3 Correct 24 ms 14812 KB Output is correct
4 Correct 34 ms 16484 KB Output is correct
5 Correct 34 ms 16484 KB Output is correct
6 Correct 27 ms 15220 KB Output is correct
7 Correct 27 ms 15208 KB Output is correct
8 Correct 32 ms 15972 KB Output is correct
9 Correct 33 ms 16028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 15436 KB Output is correct
2 Correct 1 ms 1032 KB Output is correct
3 Correct 24 ms 14812 KB Output is correct
4 Correct 34 ms 16484 KB Output is correct
5 Correct 34 ms 16484 KB Output is correct
6 Correct 27 ms 15220 KB Output is correct
7 Correct 27 ms 15208 KB Output is correct
8 Correct 32 ms 15972 KB Output is correct
9 Correct 33 ms 16028 KB Output is correct
10 Correct 25 ms 13472 KB Output is correct
11 Correct 25 ms 13336 KB Output is correct
12 Correct 26 ms 13348 KB Output is correct
13 Correct 26 ms 13328 KB Output is correct
14 Correct 26 ms 13600 KB Output is correct
15 Correct 30 ms 13976 KB Output is correct
16 Correct 31 ms 15972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 13036 KB Output is correct
2 Correct 1 ms 1024 KB Output is correct
3 Correct 22 ms 12500 KB Output is correct
4 Correct 36 ms 14312 KB Output is correct
5 Correct 32 ms 14304 KB Output is correct
6 Correct 26 ms 12980 KB Output is correct
7 Correct 26 ms 12968 KB Output is correct
8 Correct 30 ms 13676 KB Output is correct
9 Correct 30 ms 13572 KB Output is correct
10 Correct 33 ms 13384 KB Output is correct
11 Correct 33 ms 13524 KB Output is correct
12 Correct 32 ms 13272 KB Output is correct
13 Correct 33 ms 13472 KB Output is correct
14 Correct 47 ms 13732 KB Output is correct
15 Correct 34 ms 13672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 13036 KB Output is correct
2 Correct 1 ms 1024 KB Output is correct
3 Correct 22 ms 12500 KB Output is correct
4 Correct 36 ms 14312 KB Output is correct
5 Correct 32 ms 14304 KB Output is correct
6 Correct 26 ms 12980 KB Output is correct
7 Correct 26 ms 12968 KB Output is correct
8 Correct 30 ms 13676 KB Output is correct
9 Correct 30 ms 13572 KB Output is correct
10 Correct 33 ms 13384 KB Output is correct
11 Correct 33 ms 13524 KB Output is correct
12 Correct 32 ms 13272 KB Output is correct
13 Correct 33 ms 13472 KB Output is correct
14 Correct 47 ms 13732 KB Output is correct
15 Correct 34 ms 13672 KB Output is correct
16 Correct 34 ms 11532 KB Output is correct
17 Correct 25 ms 11560 KB Output is correct
18 Correct 37 ms 11424 KB Output is correct
19 Correct 26 ms 11440 KB Output is correct
20 Correct 31 ms 12056 KB Output is correct
21 Correct 36 ms 11948 KB Output is correct
22 Correct 32 ms 13836 KB Output is correct
23 Correct 37 ms 11504 KB Output is correct
24 Correct 32 ms 11616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1284 KB Output is correct
2 Correct 2 ms 1024 KB Output is correct
3 Correct 2 ms 1292 KB Output is correct
4 Correct 2 ms 1284 KB Output is correct
5 Correct 2 ms 1284 KB Output is correct
6 Correct 2 ms 1356 KB Output is correct
7 Correct 2 ms 1292 KB Output is correct
8 Correct 2 ms 1292 KB Output is correct
9 Correct 2 ms 1292 KB Output is correct
10 Correct 2 ms 1280 KB Output is correct
11 Correct 2 ms 1284 KB Output is correct
12 Correct 2 ms 1284 KB Output is correct
13 Correct 2 ms 1284 KB Output is correct
14 Correct 2 ms 1284 KB Output is correct
15 Correct 2 ms 1284 KB Output is correct
16 Correct 2 ms 1312 KB Output is correct
17 Correct 2 ms 1216 KB Output is correct
18 Correct 2 ms 1288 KB Output is correct
19 Correct 2 ms 1232 KB Output is correct
20 Correct 2 ms 1284 KB Output is correct
21 Correct 2 ms 1284 KB Output is correct
22 Correct 2 ms 1320 KB Output is correct
23 Correct 2 ms 1252 KB Output is correct
24 Correct 2 ms 1284 KB Output is correct
25 Correct 2 ms 1284 KB Output is correct
26 Correct 2 ms 1284 KB Output is correct
27 Correct 2 ms 1284 KB Output is correct
28 Correct 2 ms 1232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 10960 KB Output is correct
2 Correct 44 ms 12184 KB Output is correct
3 Correct 1 ms 1024 KB Output is correct
4 Correct 20 ms 11120 KB Output is correct
5 Correct 40 ms 13572 KB Output is correct
6 Correct 48 ms 13552 KB Output is correct
7 Correct 27 ms 12748 KB Output is correct
8 Correct 31 ms 12724 KB Output is correct
9 Correct 34 ms 13532 KB Output is correct
10 Correct 35 ms 13544 KB Output is correct
11 Correct 31 ms 13540 KB Output is correct
12 Correct 32 ms 13644 KB Output is correct
13 Correct 32 ms 13396 KB Output is correct
14 Correct 32 ms 13544 KB Output is correct
15 Correct 30 ms 13588 KB Output is correct
16 Correct 34 ms 13564 KB Output is correct
17 Correct 35 ms 13244 KB Output is correct
18 Correct 35 ms 13620 KB Output is correct
19 Correct 30 ms 13628 KB Output is correct
20 Correct 35 ms 13764 KB Output is correct
21 Correct 35 ms 13632 KB Output is correct
22 Correct 31 ms 13588 KB Output is correct
23 Correct 27 ms 11560 KB Output is correct
24 Correct 26 ms 11620 KB Output is correct
25 Correct 34 ms 12132 KB Output is correct
26 Correct 25 ms 11896 KB Output is correct
27 Correct 28 ms 12716 KB Output is correct
28 Correct 33 ms 12720 KB Output is correct
29 Correct 38 ms 12732 KB Output is correct
30 Correct 27 ms 12816 KB Output is correct
31 Correct 26 ms 11568 KB Output is correct
32 Correct 27 ms 11596 KB Output is correct
33 Correct 26 ms 11884 KB Output is correct
34 Correct 27 ms 11872 KB Output is correct
35 Correct 27 ms 12632 KB Output is correct
36 Correct 27 ms 12572 KB Output is correct
37 Correct 26 ms 12672 KB Output is correct
38 Correct 31 ms 12612 KB Output is correct
39 Correct 28 ms 12648 KB Output is correct
40 Correct 31 ms 12612 KB Output is correct
41 Correct 44 ms 13160 KB Output is correct
42 Correct 32 ms 13128 KB Output is correct
43 Correct 39 ms 13184 KB Output is correct
44 Correct 31 ms 13224 KB Output is correct
45 Correct 33 ms 13212 KB Output is correct
46 Correct 32 ms 13192 KB Output is correct
47 Correct 26 ms 12324 KB Output is correct
48 Correct 31 ms 12500 KB Output is correct
49 Correct 27 ms 12440 KB Output is correct
50 Correct 31 ms 12616 KB Output is correct
51 Correct 27 ms 11788 KB Output is correct
52 Correct 25 ms 11708 KB Output is correct
53 Correct 26 ms 11752 KB Output is correct
54 Correct 26 ms 11768 KB Output is correct
55 Correct 26 ms 11800 KB Output is correct
56 Correct 30 ms 11772 KB Output is correct
57 Correct 28 ms 11624 KB Output is correct
58 Correct 30 ms 11752 KB Output is correct
59 Correct 26 ms 11844 KB Output is correct
60 Correct 27 ms 11812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 11052 KB Output is correct
2 Correct 34 ms 11900 KB Output is correct
3 Correct 1 ms 1032 KB Output is correct
4 Correct 22 ms 11064 KB Output is correct
5 Correct 43 ms 13488 KB Output is correct
6 Correct 42 ms 13476 KB Output is correct
7 Correct 28 ms 12608 KB Output is correct
8 Correct 27 ms 13020 KB Output is correct
9 Correct 34 ms 13836 KB Output is correct
10 Correct 36 ms 13892 KB Output is correct
11 Correct 39 ms 13932 KB Output is correct
12 Correct 33 ms 13888 KB Output is correct
13 Correct 34 ms 13976 KB Output is correct
14 Correct 34 ms 14004 KB Output is correct
15 Correct 33 ms 13932 KB Output is correct
16 Correct 32 ms 14004 KB Output is correct
17 Correct 31 ms 13628 KB Output is correct
18 Correct 30 ms 13680 KB Output is correct
19 Correct 32 ms 13524 KB Output is correct
20 Correct 33 ms 13580 KB Output is correct
21 Correct 35 ms 13632 KB Output is correct
22 Correct 32 ms 13636 KB Output is correct
23 Correct 31 ms 11496 KB Output is correct
24 Correct 25 ms 11556 KB Output is correct
25 Correct 25 ms 11952 KB Output is correct
26 Correct 26 ms 11912 KB Output is correct
27 Correct 31 ms 12784 KB Output is correct
28 Correct 28 ms 12720 KB Output is correct
29 Correct 30 ms 12852 KB Output is correct
30 Correct 33 ms 12808 KB Output is correct
31 Correct 27 ms 11564 KB Output is correct
32 Correct 25 ms 11656 KB Output is correct
33 Correct 25 ms 11964 KB Output is correct
34 Correct 27 ms 12120 KB Output is correct
35 Correct 33 ms 12692 KB Output is correct
36 Correct 28 ms 12616 KB Output is correct
37 Correct 34 ms 12720 KB Output is correct
38 Correct 32 ms 12616 KB Output is correct
39 Correct 34 ms 12620 KB Output is correct
40 Correct 32 ms 12596 KB Output is correct
41 Correct 30 ms 13184 KB Output is correct
42 Correct 36 ms 13124 KB Output is correct
43 Correct 35 ms 13144 KB Output is correct
44 Correct 31 ms 13152 KB Output is correct
45 Correct 35 ms 13196 KB Output is correct
46 Correct 36 ms 13192 KB Output is correct
47 Correct 28 ms 12408 KB Output is correct
48 Correct 30 ms 12528 KB Output is correct
49 Correct 45 ms 12256 KB Output is correct
50 Correct 41 ms 12524 KB Output is correct
51 Correct 31 ms 11760 KB Output is correct
52 Correct 33 ms 11784 KB Output is correct
53 Correct 34 ms 11856 KB Output is correct
54 Correct 40 ms 11676 KB Output is correct
55 Correct 27 ms 11832 KB Output is correct
56 Correct 33 ms 11812 KB Output is correct
57 Correct 34 ms 11688 KB Output is correct
58 Correct 40 ms 11736 KB Output is correct
59 Correct 27 ms 11896 KB Output is correct
60 Correct 30 ms 11816 KB Output is correct