답안 #260632

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
260632 2020-08-10T15:34:27 Z amoo_safar 길고양이 (JOI20_stray) C++17
85 / 100
78 ms 14688 KB
#include <bits/stdc++.h>
#include "Anthony.h"

#define pb push_back

using namespace std;

typedef pair<int, int> pii;

namespace {

const int N = 2e4 + 10;

int col[N];
vector<pii> G[N];

int pat[] = {0, 1, 0, 0, 1, 1};

void DFS(int u, int p, int pt = 0){
	int cnt = 0;
	for(auto [adj, id] : G[u]){
		if(adj != p) cnt ++;
	}
	if(cnt == 0) return ;
	if(cnt == 1){
		pt = (pt + 1) % 6;
	} else {
		pt = (pat[pt] == 0 ? 1 : 0);
	}
	if(u == 0) pt = 0;


	for(auto [adj, id] : G[u]){
		if(adj != p){
			DFS(adj, u, pt);
			col[id] = pat[pt];
		}
	}
}

}

vector<int> Mark(int n, int m, int A, int B, vector<int> U, vector<int> V) {
	assert(m == n - 1);
	assert(B >= 6);
	//cerr << "Salam\n";
	for(int i = 0; i < m; i++){
		G[U[i]].pb({V[i], i});
		G[V[i]].pb({U[i], i});
	}
	DFS(0, -1);

	//cerr << "Bye\n";
	vector<int> C(m, 0);
	for(int i = 0; i < m; i++) C[i] = col[i];
	return C;
}

#ifdef safar
int main(){
	int n;
	cin >> n;
	vector<int> U1, V1, R;

	int u, v;
	for(int i = 0; i < n - 1; i++){
		cin >> u >> v;
		U1.pb(u);
		V1.pb(v);
	}
	R = Mark(n, n - 1, 2, 6, U1, V1);
	for(auto x : R) cerr << x << '\n';
}
#endif
/*
10
1 2
2 3
3 4
4 5
5 6
6 7
5 8
7 9
9 10

*/
#include <bits/stdc++.h>
#include "Catherine.h"

#define pb push_back

using namespace std;

typedef pair<int, int> pii;

namespace {

vector<int> vis, pa;
bool UP = false;


int MoveUp(vector<int> y){
	int deg = (vis.size() > 0 ? 1 : 0);
	for(auto x : y) deg += x;
	//cerr << "% " << deg << '\n';
	if(deg == 1 and !vis.empty()){
		return -1;
	}
	if(deg <= 2){
		for(int i = 0; i < 2; i++)
			if(y[i])
				return i;
	}
	//cerr << "$$ " << y[0] << ' ' << y[1] << '\n';
	int mn = 1'000'000'000;
	for(auto x : y) mn = min(x, mn);
	if(mn == 0) return -1;
	if(vis.empty())
		return (y[0] == 1 ? 0 : 1);
	return 1 - vis.back();
}

int Hand(int x){
	//cerr << "# " << x << '\n';
	if(x == -1) vis.pb(vis.back());
	else vis.pb(x);
	pa.pb(vis.back());

	return x;
}

bool Rev(){
	int sm = 3;
	for(auto x : pa) sm -= x;
	pa.pb(sm);
	for(int i = 0; i < 6; i++) pa.pb(pa[i]);
	for(int i = 0; i + 4 < (int)pa.size(); i ++){
		if((pa[i] == 0) && (pa[i+1] == 0) && (pa[i + 2] == 1) && (pa[i + 3] == 1)){
			return true;
		}
	}
	return false;
}

}  // namespace


void Init(int A, int B){
	assert(A == 2);
	assert(B >= 6);
}


int Move(vector<int> y){
	//cerr << "O\n";
	int deg = (vis.size() > 0 ? 1 : 0);
	for(auto x : y) deg += x;
	if(deg >= 3) UP = true;
	if(deg == 1) UP = true;
	//cerr << "A\n";
	if(UP) return Hand(MoveUp(y));
	//cerr << "E\n";

	if(vis.empty()){
		int idx;
		for(int i = 0; i < 2; i++) if(y[i]) idx = i;
		y[idx] -= 1;
		int idx2;
		for(int i = 0; i < 2; i++) if(y[i]) idx2 = i;
		
		pa.pb(idx2);
		return Hand(idx);
	}

	if(pa.size() < 4){
		int idx;
		for(int i = 0; i < 2; i++) if(y[i]) idx = i;
		return Hand(idx);
	}
	int idx;
	for(int i = 0; i < 2; i++) if(y[i]) idx = i;
	pa.pb(idx);

	if(Rev()){
		UP = true;
		return Hand(-1);
	}
	UP = true;
	return Hand(MoveUp(y));
}

Compilation message

Anthony.cpp: In function 'void {anonymous}::DFS(int, int, int)':
Anthony.cpp:21:19: warning: unused variable 'id' [-Wunused-variable]
  for(auto [adj, id] : G[u]){
                   ^
# 결과 실행 시간 메모리 Grader output
1 Runtime error 8 ms 2176 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 8 ms 2176 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 8 ms 2176 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 8 ms 2176 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1536 KB Output is correct
2 Correct 2 ms 1536 KB Output is correct
3 Correct 3 ms 1536 KB Output is correct
4 Correct 3 ms 1792 KB Output is correct
5 Correct 2 ms 1792 KB Output is correct
6 Correct 2 ms 1792 KB Output is correct
7 Correct 2 ms 1792 KB Output is correct
8 Correct 2 ms 1792 KB Output is correct
9 Correct 2 ms 1792 KB Output is correct
10 Correct 4 ms 1792 KB Output is correct
11 Correct 3 ms 1792 KB Output is correct
12 Correct 2 ms 1792 KB Output is correct
13 Correct 2 ms 1792 KB Output is correct
14 Correct 2 ms 1792 KB Output is correct
15 Correct 4 ms 1792 KB Output is correct
16 Correct 3 ms 1792 KB Output is correct
17 Correct 3 ms 1536 KB Output is correct
18 Correct 2 ms 1536 KB Output is correct
19 Correct 2 ms 1792 KB Output is correct
20 Correct 2 ms 1744 KB Output is correct
21 Correct 3 ms 1536 KB Output is correct
22 Correct 3 ms 1536 KB Output is correct
23 Correct 3 ms 1792 KB Output is correct
24 Correct 2 ms 1792 KB Output is correct
25 Correct 6 ms 1792 KB Output is correct
26 Correct 3 ms 1792 KB Output is correct
27 Correct 2 ms 1536 KB Output is correct
28 Correct 2 ms 1792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 11876 KB Output is correct
2 Correct 64 ms 12988 KB Output is correct
3 Correct 1 ms 1536 KB Output is correct
4 Correct 37 ms 11500 KB Output is correct
5 Correct 78 ms 14608 KB Output is correct
6 Correct 60 ms 14440 KB Output is correct
7 Correct 47 ms 13652 KB Output is correct
8 Correct 53 ms 13424 KB Output is correct
9 Correct 76 ms 14676 KB Output is correct
10 Correct 70 ms 14520 KB Output is correct
11 Correct 65 ms 14652 KB Output is correct
12 Correct 73 ms 14436 KB Output is correct
13 Correct 67 ms 14580 KB Output is correct
14 Correct 66 ms 14576 KB Output is correct
15 Correct 64 ms 14568 KB Output is correct
16 Correct 72 ms 14556 KB Output is correct
17 Correct 63 ms 14064 KB Output is correct
18 Correct 61 ms 14184 KB Output is correct
19 Correct 59 ms 14296 KB Output is correct
20 Correct 61 ms 14296 KB Output is correct
21 Correct 56 ms 14304 KB Output is correct
22 Correct 70 ms 14100 KB Output is correct
23 Correct 48 ms 11868 KB Output is correct
24 Correct 46 ms 11760 KB Output is correct
25 Correct 48 ms 12228 KB Output is correct
26 Correct 50 ms 12100 KB Output is correct
27 Correct 76 ms 13060 KB Output is correct
28 Correct 70 ms 13032 KB Output is correct
29 Correct 55 ms 13040 KB Output is correct
30 Correct 59 ms 13160 KB Output is correct
31 Correct 48 ms 11972 KB Output is correct
32 Correct 44 ms 11632 KB Output is correct
33 Correct 48 ms 12136 KB Output is correct
34 Correct 44 ms 12016 KB Output is correct
35 Correct 52 ms 13128 KB Output is correct
36 Correct 51 ms 13340 KB Output is correct
37 Correct 53 ms 13180 KB Output is correct
38 Correct 57 ms 13388 KB Output is correct
39 Correct 52 ms 13252 KB Output is correct
40 Correct 59 ms 13380 KB Output is correct
41 Correct 71 ms 13644 KB Output is correct
42 Correct 57 ms 13772 KB Output is correct
43 Correct 56 ms 13968 KB Output is correct
44 Correct 56 ms 13780 KB Output is correct
45 Correct 65 ms 13776 KB Output is correct
46 Correct 56 ms 13728 KB Output is correct
47 Correct 54 ms 13004 KB Output is correct
48 Correct 54 ms 12948 KB Output is correct
49 Correct 67 ms 12908 KB Output is correct
50 Correct 53 ms 13084 KB Output is correct
51 Correct 47 ms 12224 KB Output is correct
52 Correct 61 ms 12108 KB Output is correct
53 Correct 55 ms 12172 KB Output is correct
54 Correct 53 ms 12108 KB Output is correct
55 Correct 68 ms 12020 KB Output is correct
56 Correct 53 ms 12216 KB Output is correct
57 Correct 53 ms 12236 KB Output is correct
58 Correct 45 ms 12236 KB Output is correct
59 Correct 51 ms 11992 KB Output is correct
60 Correct 44 ms 11992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 11756 KB Output is correct
2 Correct 60 ms 12776 KB Output is correct
3 Correct 1 ms 1536 KB Output is correct
4 Correct 37 ms 11640 KB Output is correct
5 Correct 69 ms 14568 KB Output is correct
6 Correct 60 ms 14576 KB Output is correct
7 Correct 49 ms 13660 KB Output is correct
8 Correct 60 ms 13668 KB Output is correct
9 Correct 63 ms 14564 KB Output is correct
10 Correct 59 ms 14688 KB Output is correct
11 Correct 59 ms 14684 KB Output is correct
12 Correct 61 ms 14448 KB Output is correct
13 Correct 73 ms 14512 KB Output is correct
14 Correct 56 ms 14676 KB Output is correct
15 Correct 63 ms 14684 KB Output is correct
16 Correct 59 ms 14568 KB Output is correct
17 Correct 53 ms 14064 KB Output is correct
18 Correct 56 ms 14292 KB Output is correct
19 Correct 53 ms 14064 KB Output is correct
20 Correct 53 ms 14192 KB Output is correct
21 Correct 57 ms 14192 KB Output is correct
22 Correct 66 ms 14184 KB Output is correct
23 Correct 44 ms 11632 KB Output is correct
24 Correct 47 ms 11700 KB Output is correct
25 Correct 47 ms 12256 KB Output is correct
26 Correct 48 ms 12236 KB Output is correct
27 Correct 55 ms 13064 KB Output is correct
28 Correct 54 ms 12912 KB Output is correct
29 Correct 53 ms 13040 KB Output is correct
30 Correct 62 ms 13156 KB Output is correct
31 Correct 53 ms 11620 KB Output is correct
32 Correct 44 ms 11632 KB Output is correct
33 Correct 46 ms 12492 KB Output is correct
34 Correct 48 ms 12472 KB Output is correct
35 Correct 54 ms 12992 KB Output is correct
36 Correct 53 ms 13136 KB Output is correct
37 Correct 54 ms 13120 KB Output is correct
38 Correct 55 ms 13136 KB Output is correct
39 Correct 54 ms 13144 KB Output is correct
40 Correct 54 ms 13136 KB Output is correct
41 Correct 57 ms 13560 KB Output is correct
42 Correct 57 ms 13416 KB Output is correct
43 Correct 56 ms 13552 KB Output is correct
44 Correct 59 ms 13556 KB Output is correct
45 Correct 59 ms 13568 KB Output is correct
46 Correct 57 ms 13552 KB Output is correct
47 Correct 48 ms 12832 KB Output is correct
48 Correct 48 ms 12848 KB Output is correct
49 Correct 51 ms 12708 KB Output is correct
50 Correct 50 ms 12828 KB Output is correct
51 Correct 44 ms 11880 KB Output is correct
52 Correct 44 ms 11960 KB Output is correct
53 Correct 47 ms 11900 KB Output is correct
54 Correct 45 ms 11960 KB Output is correct
55 Correct 45 ms 11952 KB Output is correct
56 Correct 50 ms 12088 KB Output is correct
57 Correct 45 ms 12048 KB Output is correct
58 Correct 48 ms 11980 KB Output is correct
59 Correct 55 ms 11988 KB Output is correct
60 Correct 45 ms 11888 KB Output is correct