답안 #925981

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
925981 2024-02-12T12:17:58 Z mickey080929 길고양이 (JOI20_stray) C++17
100 / 100
42 ms 16772 KB
#include "Anthony.h"
#include <bits/stdc++.h>

using namespace std;

int seq[6] = {0, 1, 1, 0, 0, 1};

vector<int> ret;
vector<pair<int,int>> adj[20010];

void dfs(int x, int p, int idx, int pc) {
	if (adj[x].size() == 1) return;
	if (adj[x].size() == 2) {
		if (adj[x][0].first == p) swap(adj[x][0], adj[x][1]);
		if (idx == -1) idx = pc;
		ret[adj[x][0].second] = seq[(idx+1) % 6];
		dfs(adj[x][0].first, x, (idx+1) % 6, seq[(idx+1) % 6]);
		return;
	}
	for (auto &[y, i] : adj[x]) {
		if (y == p) continue;
		ret[i] = pc ^ 1;
		dfs(y, x, -1, pc ^ 1);
	}
}

vector<int> Mark(int N, int M, int A, int B, vector<int> U, vector<int> V) {
	ret.resize(M);
	for (int i=0; i<M; i++) {
		adj[U[i]].push_back({V[i], i});
		adj[V[i]].push_back({U[i], i});
	}
	if (A >= 3) {
		vector<int> dist(N, -1);
		queue<int> q;
		q.push(0);
		dist[0] = 0;
		while (!q.empty()) {
			int x = q.front();
			q.pop();
			for (auto &[y, _] : adj[x]) {
				if (dist[y] == -1) {
					dist[y] = dist[x] + 1;
					q.push(y);
				}
			}
		}
		for (int i=0; i<M; i++) {
			ret[i] = min(dist[U[i]], dist[V[i]]) % 3;
		}
		return ret;
	}
	for (auto &[y, i] : adj[0]) {
		ret[i] = 0;
		dfs(y, 0, -1, 0);
	}
	return ret;
}
#include "Catherine.h"
#include <bits/stdc++.h>

using namespace std;

int A, B;

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

int cnt = 0;
int prv = -1;
int seq[6] = {0, 1, 1, 0, 0, 1};
int read[6];

bool findDir() {
	for (int i=0; i<6; i++) {
		bool f = true;
		for (int j=0; j<6; j++) {
			if (read[(i+j) % 6] != seq[j]) {
				f = false;
				break;
			}
		}
		if (f) return true;
	}
	return false;
}

int Move(vector<int> y) {
	if (A >= 3) {
		if (y[0] && y[1]) return 0;
		if (y[1] && y[2]) return 1;
		if (y[2] && y[0]) return 2;
		if (y[0]) return 0;
		if (y[1]) return 1;
		if (y[2]) return 2;
		assert(0);
	}
	cnt ++;
	if (prv != -1) {
		if (y[0] + y[1] == 1) {
			if (y[0]) prv = 0;
			else prv = 1;
			return prv;
		}
		prv ^= 1;
		return prv;
	}
	if (cnt == 1) {
		if (y[0] == 1 && y[1] != 1) {
			return prv = 0;
		}
		if (y[0] != 1 && y[1] == 1) {
			return prv = 1;
		}
		assert(y[0] + y[1] == 2);
		if (y[0] == 2) {
			read[0] = read[1] = 0;
			return 0;
		}
		if (y[0] == 1) {
			read[0] = 0; read[1] = 1;
			return 1;
		}
		read[0] = read[1] = 1;
		return 1;
	}
	if (y[0] + y[1] != 1) {
		prv = read[cnt-1];
		if (!y[0] || !y[1]) return -1;
		assert(y[read[cnt-1] ^ 1]);
		return prv = (read[cnt-1] ^ 1);
	}
	read[cnt] = y[1];
	if (cnt == 4) {
		read[5] = 3 - read[0] - read[1] - read[2] - read[3] - read[4];
		prv = read[3];
		if (findDir()) return -1;
		return prv = read[4];
	}
	return read[cnt];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 16004 KB Output is correct
2 Correct 1 ms 1292 KB Output is correct
3 Correct 23 ms 15236 KB Output is correct
4 Correct 34 ms 16772 KB Output is correct
5 Correct 41 ms 16700 KB Output is correct
6 Correct 26 ms 15484 KB Output is correct
7 Correct 26 ms 15448 KB Output is correct
8 Correct 31 ms 16260 KB Output is correct
9 Correct 32 ms 16140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 16004 KB Output is correct
2 Correct 1 ms 1292 KB Output is correct
3 Correct 23 ms 15236 KB Output is correct
4 Correct 34 ms 16772 KB Output is correct
5 Correct 41 ms 16700 KB Output is correct
6 Correct 26 ms 15484 KB Output is correct
7 Correct 26 ms 15448 KB Output is correct
8 Correct 31 ms 16260 KB Output is correct
9 Correct 32 ms 16140 KB Output is correct
10 Correct 31 ms 13620 KB Output is correct
11 Correct 25 ms 13680 KB Output is correct
12 Correct 25 ms 13512 KB Output is correct
13 Correct 25 ms 13680 KB Output is correct
14 Correct 26 ms 13944 KB Output is correct
15 Correct 37 ms 14444 KB Output is correct
16 Correct 28 ms 16248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 13484 KB Output is correct
2 Correct 1 ms 1308 KB Output is correct
3 Correct 23 ms 12700 KB Output is correct
4 Correct 33 ms 14612 KB Output is correct
5 Correct 32 ms 14700 KB Output is correct
6 Correct 26 ms 13168 KB Output is correct
7 Correct 26 ms 13176 KB Output is correct
8 Correct 31 ms 14008 KB Output is correct
9 Correct 31 ms 13936 KB Output is correct
10 Correct 28 ms 13692 KB Output is correct
11 Correct 33 ms 13760 KB Output is correct
12 Correct 33 ms 13628 KB Output is correct
13 Correct 28 ms 13716 KB Output is correct
14 Correct 31 ms 13884 KB Output is correct
15 Correct 30 ms 13920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 13484 KB Output is correct
2 Correct 1 ms 1308 KB Output is correct
3 Correct 23 ms 12700 KB Output is correct
4 Correct 33 ms 14612 KB Output is correct
5 Correct 32 ms 14700 KB Output is correct
6 Correct 26 ms 13168 KB Output is correct
7 Correct 26 ms 13176 KB Output is correct
8 Correct 31 ms 14008 KB Output is correct
9 Correct 31 ms 13936 KB Output is correct
10 Correct 28 ms 13692 KB Output is correct
11 Correct 33 ms 13760 KB Output is correct
12 Correct 33 ms 13628 KB Output is correct
13 Correct 28 ms 13716 KB Output is correct
14 Correct 31 ms 13884 KB Output is correct
15 Correct 30 ms 13920 KB Output is correct
16 Correct 23 ms 11580 KB Output is correct
17 Correct 23 ms 11640 KB Output is correct
18 Correct 25 ms 11644 KB Output is correct
19 Correct 24 ms 11616 KB Output is correct
20 Correct 28 ms 12416 KB Output is correct
21 Correct 27 ms 12152 KB Output is correct
22 Correct 30 ms 14172 KB Output is correct
23 Correct 31 ms 12108 KB Output is correct
24 Correct 24 ms 11904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1808 KB Output is correct
2 Correct 1 ms 1312 KB Output is correct
3 Correct 2 ms 1568 KB Output is correct
4 Correct 2 ms 1568 KB Output is correct
5 Correct 2 ms 1568 KB Output is correct
6 Correct 2 ms 1568 KB Output is correct
7 Correct 1 ms 1560 KB Output is correct
8 Correct 2 ms 1564 KB Output is correct
9 Correct 2 ms 1572 KB Output is correct
10 Correct 2 ms 1572 KB Output is correct
11 Correct 2 ms 1568 KB Output is correct
12 Correct 2 ms 1572 KB Output is correct
13 Correct 2 ms 1560 KB Output is correct
14 Correct 2 ms 1568 KB Output is correct
15 Correct 2 ms 1620 KB Output is correct
16 Correct 1 ms 1572 KB Output is correct
17 Correct 2 ms 1572 KB Output is correct
18 Correct 2 ms 2064 KB Output is correct
19 Correct 2 ms 1572 KB Output is correct
20 Correct 1 ms 1572 KB Output is correct
21 Correct 2 ms 1556 KB Output is correct
22 Correct 2 ms 1560 KB Output is correct
23 Correct 2 ms 1568 KB Output is correct
24 Correct 1 ms 1556 KB Output is correct
25 Correct 2 ms 1812 KB Output is correct
26 Correct 1 ms 1568 KB Output is correct
27 Correct 2 ms 1408 KB Output is correct
28 Correct 2 ms 1576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 11392 KB Output is correct
2 Correct 27 ms 11640 KB Output is correct
3 Correct 0 ms 1296 KB Output is correct
4 Correct 20 ms 11548 KB Output is correct
5 Correct 38 ms 13144 KB Output is correct
6 Correct 33 ms 12860 KB Output is correct
7 Correct 25 ms 11856 KB Output is correct
8 Correct 26 ms 11832 KB Output is correct
9 Correct 31 ms 12884 KB Output is correct
10 Correct 28 ms 12856 KB Output is correct
11 Correct 32 ms 13080 KB Output is correct
12 Correct 28 ms 12880 KB Output is correct
13 Correct 27 ms 12892 KB Output is correct
14 Correct 28 ms 12996 KB Output is correct
15 Correct 28 ms 13016 KB Output is correct
16 Correct 28 ms 12820 KB Output is correct
17 Correct 26 ms 12548 KB Output is correct
18 Correct 34 ms 12628 KB Output is correct
19 Correct 26 ms 12624 KB Output is correct
20 Correct 27 ms 12612 KB Output is correct
21 Correct 28 ms 12456 KB Output is correct
22 Correct 27 ms 12620 KB Output is correct
23 Correct 25 ms 11836 KB Output is correct
24 Correct 25 ms 11848 KB Output is correct
25 Correct 27 ms 12032 KB Output is correct
26 Correct 25 ms 11848 KB Output is correct
27 Correct 27 ms 12372 KB Output is correct
28 Correct 27 ms 12288 KB Output is correct
29 Correct 27 ms 12324 KB Output is correct
30 Correct 33 ms 12372 KB Output is correct
31 Correct 25 ms 11752 KB Output is correct
32 Correct 25 ms 12112 KB Output is correct
33 Correct 25 ms 11900 KB Output is correct
34 Correct 26 ms 11848 KB Output is correct
35 Correct 27 ms 12256 KB Output is correct
36 Correct 27 ms 12336 KB Output is correct
37 Correct 27 ms 12360 KB Output is correct
38 Correct 27 ms 12372 KB Output is correct
39 Correct 27 ms 12372 KB Output is correct
40 Correct 27 ms 12236 KB Output is correct
41 Correct 33 ms 12628 KB Output is correct
42 Correct 28 ms 12608 KB Output is correct
43 Correct 27 ms 12612 KB Output is correct
44 Correct 30 ms 12624 KB Output is correct
45 Correct 28 ms 12556 KB Output is correct
46 Correct 28 ms 12616 KB Output is correct
47 Correct 27 ms 12224 KB Output is correct
48 Correct 27 ms 12192 KB Output is correct
49 Correct 26 ms 12104 KB Output is correct
50 Correct 27 ms 12364 KB Output is correct
51 Correct 25 ms 11784 KB Output is correct
52 Correct 24 ms 12060 KB Output is correct
53 Correct 25 ms 12076 KB Output is correct
54 Correct 25 ms 11880 KB Output is correct
55 Correct 24 ms 11852 KB Output is correct
56 Correct 27 ms 12108 KB Output is correct
57 Correct 25 ms 11584 KB Output is correct
58 Correct 25 ms 11748 KB Output is correct
59 Correct 25 ms 11864 KB Output is correct
60 Correct 28 ms 12108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 11380 KB Output is correct
2 Correct 30 ms 11644 KB Output is correct
3 Correct 1 ms 1308 KB Output is correct
4 Correct 20 ms 11584 KB Output is correct
5 Correct 32 ms 12888 KB Output is correct
6 Correct 30 ms 12856 KB Output is correct
7 Correct 26 ms 12076 KB Output is correct
8 Correct 26 ms 11768 KB Output is correct
9 Correct 27 ms 12876 KB Output is correct
10 Correct 28 ms 12724 KB Output is correct
11 Correct 31 ms 12840 KB Output is correct
12 Correct 30 ms 12848 KB Output is correct
13 Correct 30 ms 12872 KB Output is correct
14 Correct 28 ms 12792 KB Output is correct
15 Correct 33 ms 12864 KB Output is correct
16 Correct 42 ms 12844 KB Output is correct
17 Correct 26 ms 12628 KB Output is correct
18 Correct 27 ms 12444 KB Output is correct
19 Correct 27 ms 12628 KB Output is correct
20 Correct 28 ms 12620 KB Output is correct
21 Correct 33 ms 12756 KB Output is correct
22 Correct 27 ms 12416 KB Output is correct
23 Correct 28 ms 11816 KB Output is correct
24 Correct 24 ms 11760 KB Output is correct
25 Correct 26 ms 11856 KB Output is correct
26 Correct 26 ms 11832 KB Output is correct
27 Correct 30 ms 12332 KB Output is correct
28 Correct 26 ms 12372 KB Output is correct
29 Correct 28 ms 12368 KB Output is correct
30 Correct 27 ms 12368 KB Output is correct
31 Correct 25 ms 11852 KB Output is correct
32 Correct 24 ms 11712 KB Output is correct
33 Correct 24 ms 11852 KB Output is correct
34 Correct 25 ms 12012 KB Output is correct
35 Correct 29 ms 13172 KB Output is correct
36 Correct 28 ms 12336 KB Output is correct
37 Correct 34 ms 12520 KB Output is correct
38 Correct 27 ms 12180 KB Output is correct
39 Correct 27 ms 12320 KB Output is correct
40 Correct 27 ms 12364 KB Output is correct
41 Correct 27 ms 12956 KB Output is correct
42 Correct 27 ms 12624 KB Output is correct
43 Correct 27 ms 12616 KB Output is correct
44 Correct 32 ms 12624 KB Output is correct
45 Correct 30 ms 12480 KB Output is correct
46 Correct 31 ms 12564 KB Output is correct
47 Correct 27 ms 12332 KB Output is correct
48 Correct 27 ms 12168 KB Output is correct
49 Correct 26 ms 12096 KB Output is correct
50 Correct 27 ms 12264 KB Output is correct
51 Correct 31 ms 11764 KB Output is correct
52 Correct 27 ms 12008 KB Output is correct
53 Correct 25 ms 11852 KB Output is correct
54 Correct 27 ms 11936 KB Output is correct
55 Correct 26 ms 11980 KB Output is correct
56 Correct 26 ms 11776 KB Output is correct
57 Correct 26 ms 11640 KB Output is correct
58 Correct 32 ms 11936 KB Output is correct
59 Correct 25 ms 11928 KB Output is correct
60 Correct 28 ms 11972 KB Output is correct