답안 #220220

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
220220 2020-04-07T11:14:41 Z atoiz 길고양이 (JOI20_stray) C++14
100 / 100
77 ms 17420 KB
#include "Anthony.h"
#include <vector>
#include <queue>

using namespace std;

namespace Anthony_7 {
	int N, M;
	vector<int> U, V, X;
	vector<vector<int>> adj;

	void dfs(int u, int id, int path_order = -1)
	{
		if (adj[u].size() == 1) return;
		if (adj[u].size() == 2) {
			int nxt = id ^ adj[u][0] ^ adj[u][1];

			if (!~path_order) path_order = X[id];
			path_order = (path_order + 1) % 6;
			X[nxt] = (path_order == 1 || path_order == 4 || path_order == 5);
			return dfs(U[nxt] ^ V[nxt] ^ u, nxt, path_order);
		}

		int x = X[id] ^ 1;
		for (int nxt : adj[u]) if (nxt != id) {
			X[nxt] = x;
			dfs(U[nxt] ^ V[nxt] ^ u, nxt);
		}
	}

	vector<int> mark(int _N, int _M, int A, int B, vector<int> _U, vector<int> _V)
	{
		N = _N, M = _M, U = move(_U), V = move(_V);
		X.resize(M);
		adj.assign(N, vector<int>(0));
		for (int i = 0; i < M; ++i) {
			adj[U[i]].push_back(i);
			adj[V[i]].push_back(i);
		}
		for (int id : adj[0]) {
			X[id] = 0;
			dfs(U[id] ^ V[id], id);
		}
		return X;
	}
}

namespace Anthony_4 {
	int N, M;
	vector<int> U, V, X;
	vector<vector<int>> adj;

	vector<int> mark(int _N, int _M, int A, int B, vector<int> _U, vector<int> _V)
	{
		N = _N, M = _M, U = move(_U), V = move(_V);
		X.resize(M);
		adj.assign(N, vector<int>(0));
		for (int i = 0; i < M; ++i) {
			adj[U[i]].push_back(i);
			adj[V[i]].push_back(i);
		}

		vector<int> dist(N, N + 5);
		queue<int> qu;
		qu.push(0), dist[0] = 0;
		while (!qu.empty()) {
			int u = qu.front(); qu.pop();
			for (int id : adj[u]) {
				int v = U[id] ^ V[id] ^ u;
				if (dist[u] + 1 < dist[v]) {
					dist[v] = dist[u] + 1;
					qu.push(v);
				}
			}
		}

		for (int i = 0; i < M; ++i) {
			X[i] = min(dist[U[i]], dist[V[i]]) % 3;
		}
		return X;
	}
}


vector<int> Mark(int N, int M, int A, int B, vector<int> U, vector<int> V)
{ 
	if (A == 2) return Anthony_7::mark(N, M, A, B, U, V);
	else return Anthony_4::mark(N, M, A, B, U, V);
}
#include "Catherine.h"
#include <vector>
#include <cassert>
#include <numeric>
#include <iostream>

using namespace std;

namespace Catherine_7 {
	bool confused = true;
	int last_col = -1;
	vector<int> prev_cols;

	void init(int _A, int _B)
	{
		confused = true;
		last_col = -1;
		prev_cols.clear();
	}

	int move(vector<int> Y)
	{
		int deg = accumulate(Y.begin(), Y.end(), int(last_col != -1));

		if (deg != 2) {
			if (~last_col) ++Y[last_col];
			confused = false;
			for (int i = 0; i < (int) Y.size(); ++i) {
				if (Y[i] == 1) {
					if (i == last_col) return -1;
					return last_col = i;
				}
			}
			assert(0);
		}

		if (not confused) { // wait up
			assert(~last_col);
			for (int i = 0; i < (int) Y.size(); ++i) {
				if (Y[i] == 1) {
					return last_col = i;
				}
			}
			assert(0);
		}

		for (int i = 0; i < (int) Y.size(); ++i) {
			for (int j = 0; j < Y[i]; ++j) {
				prev_cols.push_back(i);
			}
		}

		cerr << "prev ";
		for (int x : prev_cols) cerr << x << ' ';
		cerr << endl;

		for (int i = 0; i < (int) prev_cols.size() - 1; ++i) if (prev_cols[i] == prev_cols[i + 1]) {
			if (i - 2 >= 0) {
				confused = false;
				if (prev_cols[i - 2] == 0) return last_col = prev_cols[prev_cols.size() - 2], -1;
				else return last_col = prev_cols.back();
			}
			if (i + 3 < (int) prev_cols.size()) {
				confused = false;
				if (prev_cols[i + 3] == 1) return last_col = prev_cols[prev_cols.size() - 2], -1;
				else return last_col = prev_cols.back();
			}
		}
		assert((int) prev_cols.size() < 5);

		return last_col = prev_cols.back();
	}
}

namespace Catherine_4 {
	void init(int A, int B) {}

	int move(vector<int> Y)
	{
		if (!Y[2] && Y[0]) return 0;
		if (!Y[0] && Y[1]) return 1;
		if (!Y[1] && Y[2]) return 2;
		assert(0);
	}
}

void Init(int A, int B)
{
	if (A == 2) Catherine_7::init(A, B);
	else Catherine_4::init(A, B);
}

int Move(vector<int> Y)
{
	if ((int) Y.size() == 2) return Catherine_7::move(Y);
	else return Catherine_4::move(Y);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 16248 KB Output is correct
2 Correct 9 ms 776 KB Output is correct
3 Correct 48 ms 15588 KB Output is correct
4 Correct 74 ms 17368 KB Output is correct
5 Correct 69 ms 17420 KB Output is correct
6 Correct 54 ms 15984 KB Output is correct
7 Correct 64 ms 16220 KB Output is correct
8 Correct 63 ms 16716 KB Output is correct
9 Correct 63 ms 16736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 16248 KB Output is correct
2 Correct 9 ms 776 KB Output is correct
3 Correct 48 ms 15588 KB Output is correct
4 Correct 74 ms 17368 KB Output is correct
5 Correct 69 ms 17420 KB Output is correct
6 Correct 54 ms 15984 KB Output is correct
7 Correct 64 ms 16220 KB Output is correct
8 Correct 63 ms 16716 KB Output is correct
9 Correct 63 ms 16736 KB Output is correct
10 Correct 50 ms 14036 KB Output is correct
11 Correct 56 ms 13932 KB Output is correct
12 Correct 51 ms 14084 KB Output is correct
13 Correct 51 ms 14084 KB Output is correct
14 Correct 56 ms 14380 KB Output is correct
15 Correct 62 ms 14896 KB Output is correct
16 Correct 64 ms 16980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 13812 KB Output is correct
2 Correct 10 ms 776 KB Output is correct
3 Correct 49 ms 13436 KB Output is correct
4 Correct 66 ms 15080 KB Output is correct
5 Correct 66 ms 15236 KB Output is correct
6 Correct 53 ms 13780 KB Output is correct
7 Correct 54 ms 14024 KB Output is correct
8 Correct 63 ms 14540 KB Output is correct
9 Correct 61 ms 14456 KB Output is correct
10 Correct 56 ms 14328 KB Output is correct
11 Correct 64 ms 14320 KB Output is correct
12 Correct 59 ms 14164 KB Output is correct
13 Correct 56 ms 14324 KB Output is correct
14 Correct 62 ms 14588 KB Output is correct
15 Correct 62 ms 14432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 13812 KB Output is correct
2 Correct 10 ms 776 KB Output is correct
3 Correct 49 ms 13436 KB Output is correct
4 Correct 66 ms 15080 KB Output is correct
5 Correct 66 ms 15236 KB Output is correct
6 Correct 53 ms 13780 KB Output is correct
7 Correct 54 ms 14024 KB Output is correct
8 Correct 63 ms 14540 KB Output is correct
9 Correct 61 ms 14456 KB Output is correct
10 Correct 56 ms 14328 KB Output is correct
11 Correct 64 ms 14320 KB Output is correct
12 Correct 59 ms 14164 KB Output is correct
13 Correct 56 ms 14324 KB Output is correct
14 Correct 62 ms 14588 KB Output is correct
15 Correct 62 ms 14432 KB Output is correct
16 Correct 47 ms 12348 KB Output is correct
17 Correct 47 ms 12108 KB Output is correct
18 Correct 50 ms 12172 KB Output is correct
19 Correct 50 ms 12300 KB Output is correct
20 Correct 56 ms 12740 KB Output is correct
21 Correct 53 ms 12588 KB Output is correct
22 Correct 57 ms 14720 KB Output is correct
23 Correct 50 ms 12316 KB Output is correct
24 Correct 51 ms 12316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 1144 KB Output is correct
2 Correct 9 ms 792 KB Output is correct
3 Correct 10 ms 1168 KB Output is correct
4 Correct 10 ms 1040 KB Output is correct
5 Correct 10 ms 1040 KB Output is correct
6 Correct 10 ms 1168 KB Output is correct
7 Correct 11 ms 1240 KB Output is correct
8 Correct 10 ms 1108 KB Output is correct
9 Correct 10 ms 1140 KB Output is correct
10 Correct 10 ms 1040 KB Output is correct
11 Correct 10 ms 1268 KB Output is correct
12 Correct 10 ms 1144 KB Output is correct
13 Correct 10 ms 1252 KB Output is correct
14 Correct 10 ms 1104 KB Output is correct
15 Correct 10 ms 1140 KB Output is correct
16 Correct 10 ms 1132 KB Output is correct
17 Correct 10 ms 1132 KB Output is correct
18 Correct 10 ms 1020 KB Output is correct
19 Correct 10 ms 1140 KB Output is correct
20 Correct 10 ms 1136 KB Output is correct
21 Correct 11 ms 1136 KB Output is correct
22 Correct 10 ms 1140 KB Output is correct
23 Correct 10 ms 1140 KB Output is correct
24 Correct 10 ms 1132 KB Output is correct
25 Correct 10 ms 1144 KB Output is correct
26 Correct 11 ms 1128 KB Output is correct
27 Correct 10 ms 1248 KB Output is correct
28 Correct 10 ms 1268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 11988 KB Output is correct
2 Correct 55 ms 12684 KB Output is correct
3 Correct 9 ms 796 KB Output is correct
4 Correct 43 ms 11772 KB Output is correct
5 Correct 62 ms 13264 KB Output is correct
6 Correct 62 ms 13148 KB Output is correct
7 Correct 52 ms 12244 KB Output is correct
8 Correct 52 ms 12380 KB Output is correct
9 Correct 62 ms 13244 KB Output is correct
10 Correct 63 ms 13140 KB Output is correct
11 Correct 77 ms 13112 KB Output is correct
12 Correct 63 ms 13132 KB Output is correct
13 Correct 61 ms 13264 KB Output is correct
14 Correct 67 ms 13256 KB Output is correct
15 Correct 62 ms 13136 KB Output is correct
16 Correct 61 ms 13132 KB Output is correct
17 Correct 57 ms 12752 KB Output is correct
18 Correct 56 ms 12872 KB Output is correct
19 Correct 57 ms 12756 KB Output is correct
20 Correct 60 ms 12848 KB Output is correct
21 Correct 57 ms 12756 KB Output is correct
22 Correct 57 ms 12872 KB Output is correct
23 Correct 51 ms 12088 KB Output is correct
24 Correct 54 ms 12012 KB Output is correct
25 Correct 51 ms 12188 KB Output is correct
26 Correct 51 ms 12220 KB Output is correct
27 Correct 55 ms 12812 KB Output is correct
28 Correct 56 ms 12800 KB Output is correct
29 Correct 57 ms 12668 KB Output is correct
30 Correct 57 ms 12808 KB Output is correct
31 Correct 49 ms 12084 KB Output is correct
32 Correct 49 ms 12076 KB Output is correct
33 Correct 49 ms 12072 KB Output is correct
34 Correct 49 ms 12180 KB Output is correct
35 Correct 55 ms 12628 KB Output is correct
36 Correct 54 ms 12696 KB Output is correct
37 Correct 56 ms 12684 KB Output is correct
38 Correct 55 ms 12548 KB Output is correct
39 Correct 55 ms 12704 KB Output is correct
40 Correct 56 ms 12700 KB Output is correct
41 Correct 62 ms 12880 KB Output is correct
42 Correct 61 ms 12996 KB Output is correct
43 Correct 60 ms 12752 KB Output is correct
44 Correct 64 ms 13108 KB Output is correct
45 Correct 57 ms 13132 KB Output is correct
46 Correct 64 ms 12748 KB Output is correct
47 Correct 56 ms 12488 KB Output is correct
48 Correct 53 ms 12616 KB Output is correct
49 Correct 54 ms 12468 KB Output is correct
50 Correct 57 ms 12720 KB Output is correct
51 Correct 51 ms 12232 KB Output is correct
52 Correct 50 ms 12360 KB Output is correct
53 Correct 50 ms 12244 KB Output is correct
54 Correct 50 ms 12356 KB Output is correct
55 Correct 54 ms 12364 KB Output is correct
56 Correct 50 ms 12248 KB Output is correct
57 Correct 51 ms 12364 KB Output is correct
58 Correct 51 ms 12536 KB Output is correct
59 Correct 54 ms 12240 KB Output is correct
60 Correct 51 ms 12240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 12204 KB Output is correct
2 Correct 53 ms 12444 KB Output is correct
3 Correct 9 ms 900 KB Output is correct
4 Correct 43 ms 11700 KB Output is correct
5 Correct 61 ms 13140 KB Output is correct
6 Correct 61 ms 13132 KB Output is correct
7 Correct 51 ms 12244 KB Output is correct
8 Correct 52 ms 12248 KB Output is correct
9 Correct 61 ms 13016 KB Output is correct
10 Correct 62 ms 13140 KB Output is correct
11 Correct 69 ms 13148 KB Output is correct
12 Correct 62 ms 13228 KB Output is correct
13 Correct 62 ms 13092 KB Output is correct
14 Correct 63 ms 13148 KB Output is correct
15 Correct 62 ms 13020 KB Output is correct
16 Correct 63 ms 13256 KB Output is correct
17 Correct 57 ms 12916 KB Output is correct
18 Correct 60 ms 12880 KB Output is correct
19 Correct 59 ms 13216 KB Output is correct
20 Correct 56 ms 12764 KB Output is correct
21 Correct 57 ms 12620 KB Output is correct
22 Correct 60 ms 12756 KB Output is correct
23 Correct 50 ms 12080 KB Output is correct
24 Correct 48 ms 12072 KB Output is correct
25 Correct 52 ms 12208 KB Output is correct
26 Correct 52 ms 12220 KB Output is correct
27 Correct 60 ms 12824 KB Output is correct
28 Correct 55 ms 12800 KB Output is correct
29 Correct 55 ms 12816 KB Output is correct
30 Correct 55 ms 12808 KB Output is correct
31 Correct 49 ms 12088 KB Output is correct
32 Correct 49 ms 11988 KB Output is correct
33 Correct 51 ms 12336 KB Output is correct
34 Correct 51 ms 12328 KB Output is correct
35 Correct 56 ms 12672 KB Output is correct
36 Correct 70 ms 12924 KB Output is correct
37 Correct 56 ms 12692 KB Output is correct
38 Correct 55 ms 12688 KB Output is correct
39 Correct 57 ms 12636 KB Output is correct
40 Correct 62 ms 12688 KB Output is correct
41 Correct 61 ms 12880 KB Output is correct
42 Correct 56 ms 12748 KB Output is correct
43 Correct 60 ms 12764 KB Output is correct
44 Correct 66 ms 13004 KB Output is correct
45 Correct 59 ms 13104 KB Output is correct
46 Correct 63 ms 13124 KB Output is correct
47 Correct 60 ms 12612 KB Output is correct
48 Correct 56 ms 12368 KB Output is correct
49 Correct 60 ms 12248 KB Output is correct
50 Correct 55 ms 12740 KB Output is correct
51 Correct 50 ms 12116 KB Output is correct
52 Correct 48 ms 12364 KB Output is correct
53 Correct 51 ms 12236 KB Output is correct
54 Correct 50 ms 12360 KB Output is correct
55 Correct 51 ms 12332 KB Output is correct
56 Correct 50 ms 12340 KB Output is correct
57 Correct 55 ms 12240 KB Output is correct
58 Correct 55 ms 12124 KB Output is correct
59 Correct 49 ms 12364 KB Output is correct
60 Correct 50 ms 12240 KB Output is correct