답안 #246351

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
246351 2020-07-08T19:22:22 Z kostia244 길고양이 (JOI20_stray) C++17
100 / 100
79 ms 22912 KB
#include "Anthony.h"
#include <bits/stdc++.h>
#define pb push_back
using namespace std;


namespace anton {
const int maxn = 1<<17;
vector<int> val, p, pidx, col,  god = {0, 0, 1, 0, 1, 1};
vector<array<int, 2>> g[maxn];
void dfs(int v) {
	for(auto &[i, idx] : g[v]) if(i != p[v]) {
		p[i] = v, pidx[i] = idx;
		col[i] = col[v]^1;
		dfs(i);
	}
	//cout << v << " // " << col[v] << '\n';
	if(!v || g[v].size() == 2) return;
	int u = p[v];
	vector<int> l {v};
	while(u && g[u].size() == 2) {
		l.pb(u);
		u = p[u];
	}
	int b = 0;
	while(god[b] != col[v] || god[(b + l.size() - 1)%6] != col[l.back()]) b++;
	//cout << v << " /// " << b << endl;
	//cout << god[b] << " vs " << col[v] << '\n';
	for(int i = 0; i < l.size(); i++) val[pidx[l[i]]] = god[(i+b)%6];
}

} 

namespace antOn {
const int maxn = 1<<17;
	vector<array<int, 2>> g[maxn];
	vector<int> val, lvl;
	queue<int> q;
	void solve() {
		lvl[0] = 0;
		q.push(0);
		vector<array<int, 3>> edges(val.size());
		while(!q.empty()) {
			int u = q.front();
			q.pop();
			for(auto &[i, idx] : g[u]) {
				if(lvl[i] == -1) {
					lvl[i] = lvl[u] + 1;
					q.push(i);
				}
				edges[idx] = {i, u, idx};
			}
		}
		map<int, map<int, int>> col;
		col[1][0] = col[0][1] = 0;
		col[2][1] = col[1][2] = 1;
		col[0][2] = col[2][0] = 2;
		col[0][0] = 0;
		col[1][1] = 1;
		col[2][2] = 2;
		for(auto [u, v, idx] : edges) val[idx] = col[lvl[u]%3][lvl[v]%3];
	}
}

std::vector<int> Mark(int N, int M, int A, int B,
                      std::vector<int> U, std::vector<int> V) {
	if(B == 0) {
	  for(int i = 0; i < M; i++) {
		antOn::g[U[i]].pb({V[i], i});
		antOn::g[V[i]].pb({U[i], i});
	}
	antOn::val.resize(M);
	antOn::lvl.resize(N, -1);
	antOn::solve();
	return antOn::val;
  }
  using namespace anton;
  val.resize(M);
  for(int i = 0; i < M; i++) {
	  g[U[i]].pb({V[i], i});
	  g[V[i]].pb({U[i], i});
  }
  p.resize(N);
  pidx.resize(N);
  col.resize(N);
  dfs(0);
  //for(int i = 0; i < M; i++) cout << U[i] << " " << V[i] << " " << val[i] << '\n';
  return val;
}
#include "Catherine.h"
#include <bits/stdc++.h>
#define pb push_back
using namespace std;

namespace kate {

int A, B, gg = 0, lst = -2, mvs = 0;
string cur, god = "110100110100";
int decide(vector<int> c) {
	if(B == 0) {
		if(!c[0] && !c[1]) return 2;
		if(!c[0] && !c[2]) return 1;
		if(!c[1] && !c[2]) return 0;
		if(c[0] && c[1]) return 0;
		if(c[2] && c[1]) return 1;
		if(c[2] && c[0]) return 2;
	}
	if(mvs++ > 10 && !gg) exit(-1);
	if(c[0] + c[1] == 0) {
		gg = 1;
		return -1;
	}
	if(lst == -2 && c[0]+c[1] == 1) {
		gg = 1;
		return lst = c[1];
	}
	if(c[0] + c[1] + (lst != -2) > 2) {
		gg = 1;
		if(c[0] == 0) return -1;
		if(c[1] == 0) return -1;
		if(c[0] == 1 && lst != 0) return lst = 0;
		if(c[1] == 1 && lst != 1) return lst = 1;
		exit(-1);
	}
	if(c[0] + c[1] == 2) {
		if(c[0]) {
			cur.pb('0'+c[1]);
			cur.pb('0');
			return lst = 0;
		}
		cur += "11";
		return lst = 1;
	}
	if(gg) return lst = c[1];
	cur.pb('0'+c[1]);
	if(cur.size() == 5) {
		gg = 1;
		//cout << " " << gg << "Yay\n";
		if(god.find(cur) != string::npos) return -1;
	}
	return lst = c[1];
}


}  // namespace

void Init(int A, int B) {
	kate::A = A;
	kate::B = B;
}

int Move(std::vector<int> y) {
	//cout << y[0] << " " << y[1] << " go ";
	int t = kate::decide(y);
	//cout <<kate::cur << " " << t << endl;
	return t;
}

Compilation message

Anthony.cpp: In function 'void anton::dfs(int)':
Anthony.cpp:29:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < l.size(); i++) val[pidx[l[i]]] = god[(i+b)%6];
                 ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 62 ms 21656 KB Output is correct
2 Correct 12 ms 12800 KB Output is correct
3 Correct 51 ms 21004 KB Output is correct
4 Correct 72 ms 22664 KB Output is correct
5 Correct 72 ms 22912 KB Output is correct
6 Correct 60 ms 21392 KB Output is correct
7 Correct 60 ms 21532 KB Output is correct
8 Correct 67 ms 22160 KB Output is correct
9 Correct 77 ms 22212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 62 ms 21656 KB Output is correct
2 Correct 12 ms 12800 KB Output is correct
3 Correct 51 ms 21004 KB Output is correct
4 Correct 72 ms 22664 KB Output is correct
5 Correct 72 ms 22912 KB Output is correct
6 Correct 60 ms 21392 KB Output is correct
7 Correct 60 ms 21532 KB Output is correct
8 Correct 67 ms 22160 KB Output is correct
9 Correct 77 ms 22212 KB Output is correct
10 Correct 54 ms 19604 KB Output is correct
11 Correct 54 ms 19640 KB Output is correct
12 Correct 56 ms 19932 KB Output is correct
13 Correct 55 ms 19816 KB Output is correct
14 Correct 57 ms 20020 KB Output is correct
15 Correct 61 ms 20556 KB Output is correct
16 Correct 64 ms 22376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 19328 KB Output is correct
2 Correct 12 ms 13056 KB Output is correct
3 Correct 60 ms 18860 KB Output is correct
4 Correct 68 ms 20616 KB Output is correct
5 Correct 79 ms 20736 KB Output is correct
6 Correct 63 ms 19436 KB Output is correct
7 Correct 60 ms 19320 KB Output is correct
8 Correct 65 ms 20032 KB Output is correct
9 Correct 64 ms 20020 KB Output is correct
10 Correct 62 ms 19768 KB Output is correct
11 Correct 59 ms 19780 KB Output is correct
12 Correct 62 ms 19792 KB Output is correct
13 Correct 60 ms 19756 KB Output is correct
14 Correct 64 ms 20040 KB Output is correct
15 Correct 66 ms 20036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 19328 KB Output is correct
2 Correct 12 ms 13056 KB Output is correct
3 Correct 60 ms 18860 KB Output is correct
4 Correct 68 ms 20616 KB Output is correct
5 Correct 79 ms 20736 KB Output is correct
6 Correct 63 ms 19436 KB Output is correct
7 Correct 60 ms 19320 KB Output is correct
8 Correct 65 ms 20032 KB Output is correct
9 Correct 64 ms 20020 KB Output is correct
10 Correct 62 ms 19768 KB Output is correct
11 Correct 59 ms 19780 KB Output is correct
12 Correct 62 ms 19792 KB Output is correct
13 Correct 60 ms 19756 KB Output is correct
14 Correct 64 ms 20040 KB Output is correct
15 Correct 66 ms 20036 KB Output is correct
16 Correct 52 ms 17688 KB Output is correct
17 Correct 51 ms 17932 KB Output is correct
18 Correct 52 ms 17888 KB Output is correct
19 Correct 54 ms 17888 KB Output is correct
20 Correct 57 ms 18644 KB Output is correct
21 Correct 57 ms 18352 KB Output is correct
22 Correct 63 ms 20208 KB Output is correct
23 Correct 53 ms 18016 KB Output is correct
24 Correct 54 ms 18144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 13056 KB Output is correct
2 Correct 12 ms 13056 KB Output is correct
3 Correct 13 ms 13056 KB Output is correct
4 Correct 13 ms 13056 KB Output is correct
5 Correct 13 ms 13056 KB Output is correct
6 Correct 13 ms 13056 KB Output is correct
7 Correct 13 ms 13056 KB Output is correct
8 Correct 13 ms 13056 KB Output is correct
9 Correct 13 ms 13056 KB Output is correct
10 Correct 13 ms 13056 KB Output is correct
11 Correct 13 ms 13056 KB Output is correct
12 Correct 13 ms 13056 KB Output is correct
13 Correct 13 ms 13056 KB Output is correct
14 Correct 13 ms 13040 KB Output is correct
15 Correct 15 ms 13056 KB Output is correct
16 Correct 13 ms 13056 KB Output is correct
17 Correct 13 ms 13056 KB Output is correct
18 Correct 15 ms 13056 KB Output is correct
19 Correct 13 ms 13056 KB Output is correct
20 Correct 13 ms 13056 KB Output is correct
21 Correct 14 ms 13056 KB Output is correct
22 Correct 13 ms 13056 KB Output is correct
23 Correct 13 ms 13056 KB Output is correct
24 Correct 13 ms 13056 KB Output is correct
25 Correct 13 ms 13056 KB Output is correct
26 Correct 13 ms 13056 KB Output is correct
27 Correct 13 ms 13056 KB Output is correct
28 Correct 13 ms 13056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 17716 KB Output is correct
2 Correct 62 ms 19052 KB Output is correct
3 Correct 12 ms 13056 KB Output is correct
4 Correct 48 ms 17604 KB Output is correct
5 Correct 65 ms 20312 KB Output is correct
6 Correct 66 ms 20444 KB Output is correct
7 Correct 57 ms 20064 KB Output is correct
8 Correct 55 ms 19760 KB Output is correct
9 Correct 72 ms 20320 KB Output is correct
10 Correct 65 ms 20452 KB Output is correct
11 Correct 66 ms 20312 KB Output is correct
12 Correct 67 ms 20448 KB Output is correct
13 Correct 69 ms 20440 KB Output is correct
14 Correct 67 ms 20388 KB Output is correct
15 Correct 75 ms 20304 KB Output is correct
16 Correct 71 ms 20568 KB Output is correct
17 Correct 65 ms 20060 KB Output is correct
18 Correct 64 ms 20196 KB Output is correct
19 Correct 64 ms 20056 KB Output is correct
20 Correct 66 ms 20060 KB Output is correct
21 Correct 66 ms 20048 KB Output is correct
22 Correct 67 ms 20060 KB Output is correct
23 Correct 61 ms 17720 KB Output is correct
24 Correct 55 ms 17568 KB Output is correct
25 Correct 55 ms 18096 KB Output is correct
26 Correct 56 ms 18088 KB Output is correct
27 Correct 61 ms 19176 KB Output is correct
28 Correct 61 ms 19172 KB Output is correct
29 Correct 65 ms 19120 KB Output is correct
30 Correct 61 ms 19124 KB Output is correct
31 Correct 56 ms 17780 KB Output is correct
32 Correct 57 ms 17840 KB Output is correct
33 Correct 56 ms 18056 KB Output is correct
34 Correct 62 ms 18072 KB Output is correct
35 Correct 61 ms 18812 KB Output is correct
36 Correct 63 ms 19100 KB Output is correct
37 Correct 60 ms 18852 KB Output is correct
38 Correct 61 ms 18836 KB Output is correct
39 Correct 61 ms 18852 KB Output is correct
40 Correct 60 ms 18864 KB Output is correct
41 Correct 65 ms 19536 KB Output is correct
42 Correct 64 ms 19536 KB Output is correct
43 Correct 64 ms 19528 KB Output is correct
44 Correct 63 ms 19668 KB Output is correct
45 Correct 63 ms 19580 KB Output is correct
46 Correct 64 ms 19664 KB Output is correct
47 Correct 60 ms 18680 KB Output is correct
48 Correct 62 ms 18788 KB Output is correct
49 Correct 57 ms 18556 KB Output is correct
50 Correct 59 ms 18684 KB Output is correct
51 Correct 54 ms 17936 KB Output is correct
52 Correct 55 ms 17908 KB Output is correct
53 Correct 56 ms 17936 KB Output is correct
54 Correct 56 ms 17916 KB Output is correct
55 Correct 59 ms 18056 KB Output is correct
56 Correct 54 ms 17940 KB Output is correct
57 Correct 55 ms 17908 KB Output is correct
58 Correct 59 ms 17976 KB Output is correct
59 Correct 63 ms 17788 KB Output is correct
60 Correct 55 ms 17832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 17720 KB Output is correct
2 Correct 60 ms 18888 KB Output is correct
3 Correct 13 ms 13056 KB Output is correct
4 Correct 49 ms 17532 KB Output is correct
5 Correct 70 ms 20432 KB Output is correct
6 Correct 66 ms 20432 KB Output is correct
7 Correct 61 ms 19808 KB Output is correct
8 Correct 57 ms 19808 KB Output is correct
9 Correct 75 ms 20308 KB Output is correct
10 Correct 68 ms 20308 KB Output is correct
11 Correct 66 ms 20304 KB Output is correct
12 Correct 67 ms 20268 KB Output is correct
13 Correct 66 ms 20444 KB Output is correct
14 Correct 68 ms 20436 KB Output is correct
15 Correct 66 ms 20428 KB Output is correct
16 Correct 66 ms 20324 KB Output is correct
17 Correct 62 ms 20064 KB Output is correct
18 Correct 64 ms 20012 KB Output is correct
19 Correct 63 ms 19920 KB Output is correct
20 Correct 69 ms 20264 KB Output is correct
21 Correct 62 ms 20060 KB Output is correct
22 Correct 64 ms 20056 KB Output is correct
23 Correct 54 ms 17728 KB Output is correct
24 Correct 54 ms 17736 KB Output is correct
25 Correct 54 ms 18100 KB Output is correct
26 Correct 58 ms 18096 KB Output is correct
27 Correct 66 ms 19152 KB Output is correct
28 Correct 73 ms 19060 KB Output is correct
29 Correct 61 ms 19184 KB Output is correct
30 Correct 62 ms 19152 KB Output is correct
31 Correct 55 ms 17928 KB Output is correct
32 Correct 55 ms 17660 KB Output is correct
33 Correct 63 ms 18072 KB Output is correct
34 Correct 55 ms 18056 KB Output is correct
35 Correct 68 ms 18844 KB Output is correct
36 Correct 66 ms 18676 KB Output is correct
37 Correct 62 ms 18868 KB Output is correct
38 Correct 73 ms 18996 KB Output is correct
39 Correct 64 ms 18812 KB Output is correct
40 Correct 62 ms 18856 KB Output is correct
41 Correct 63 ms 19536 KB Output is correct
42 Correct 71 ms 19516 KB Output is correct
43 Correct 68 ms 19532 KB Output is correct
44 Correct 68 ms 19664 KB Output is correct
45 Correct 66 ms 19668 KB Output is correct
46 Correct 63 ms 19628 KB Output is correct
47 Correct 57 ms 18692 KB Output is correct
48 Correct 61 ms 18560 KB Output is correct
49 Correct 57 ms 18556 KB Output is correct
50 Correct 61 ms 18688 KB Output is correct
51 Correct 54 ms 17936 KB Output is correct
52 Correct 56 ms 17940 KB Output is correct
53 Correct 54 ms 17940 KB Output is correct
54 Correct 55 ms 17940 KB Output is correct
55 Correct 54 ms 17944 KB Output is correct
56 Correct 54 ms 17952 KB Output is correct
57 Correct 53 ms 17908 KB Output is correct
58 Correct 54 ms 18140 KB Output is correct
59 Correct 60 ms 17860 KB Output is correct
60 Correct 57 ms 17860 KB Output is correct