Submission #516829

# Submission time Handle Problem Language Result Execution time Memory
516829 2022-01-22T07:19:46 Z jamezzz Stray Cat (JOI20_stray) C++17
100 / 100
61 ms 20656 KB
#include "Anthony.h"
#include <bits/stdc++.h>
using namespace std;

int seq[6]={0,1,0,0,1,1};
vector<int> col,par,AL[200005];

void dfs(int u,int pv){
	if(AL[u].size()>2){
		for(int v:AL[u]){
			if(v==par[u])continue;
			col[v]=(seq[pv]==0)?1:0;
			par[v]=u;
			dfs(v,(seq[pv]==0)?1:0);
		}
	}
	else{
		for(int v:AL[u]){
			if(v==par[u])continue;
			col[v]=seq[(pv+1)%6];
			par[v]=u;
			dfs(v,(pv+1)%6);
		}
	}
}

vector<int> Mark(int N,int M,int A,int B,vector<int> U,vector<int> V){
	if(A>=3){
		vector<int> dist(N,-1);
		for(int i=0;i<M;++i){
			AL[U[i]].push_back(V[i]);
			AL[V[i]].push_back(U[i]);
		}
		queue<int> q;
		dist[0]=0;q.push(0);
		while(!q.empty()){
			int u=q.front();q.pop();
			for(int v:AL[u]){
				if(dist[v]==-1){
					dist[v]=dist[u]+1;
					q.push(v);
				}
			}
		}
		vector<int> X(M);
		for(int i=0;i<M;++i){
			if(dist[U[i]]!=dist[V[i]])X[i]=(dist[U[i]]+dist[V[i]])%3;
			else X[i]=(2*dist[U[i]]+1)%3;
		}
		return X;
	}
	else{
		col.resize(N);
		par.resize(N,-1);
		for(int i=0;i<M;++i){
			AL[U[i]].push_back(V[i]);
			AL[V[i]].push_back(U[i]);
		}
		dfs(0,5);
		vector<int> X(M);
		for(int i=0;i<M;++i){
			if(par[U[i]]==V[i])X[i]=col[U[i]];
			else X[i]=col[V[i]];
		}
		return X;
	}
}
#include "Catherine.h"
#include <bits/stdc++.h>
using namespace std;

bool tree=true,found=false;
int mask,cnt;
int pv=-1;

int check[6]={25,18,5,11,22,12};

void Init(int A, int B){
	if(A>=3)tree=false;
}

int Move(vector<int> y){
	if(!tree){
		if(y[0]==0&&y[1]==0)return 2;
		if(y[0]==0&&y[2]==0)return 1;
		if(y[1]==0&&y[2]==0)return 0;
		if(y[0]==0)return 2;
		if(y[1]==0)return 0;
		if(y[2]==0)return 1;
	}
	else{
		//handle degree >=3
		if(pv==-1&&y[0]+y[1]>=3){
			found=true;
			return pv=(y[0]>1)?1:0;
		}
		if(pv!=-1&&y[0]+y[1]>=2){
			found=true;
			if(y[0]+(pv==0)>1)return (pv==1)?-1:pv=1;
			else return (pv==0)?-1:pv=0;
		}
		//if we know which way to go
		if(found)return pv=(y[0]==1)?0:1;
		
		//first node
		if(pv==-1){
			//leaf node
			if(y[0]==0&&y[1]==1){
				found=true;
				return pv=1;
			}
			if(y[1]==0&&y[0]==1){
				found=true;
				return pv=0;
			}
			
			if(y[0]==1&&y[1]==1){
				mask=1;
				++cnt;
				return pv=1;
			}
			else if(y[0]==2){
				mask=0;
				++cnt;
				return pv=0;
			}
			else{
				mask=3;
				++cnt;
				return pv=1;
			}
		}
		else{
			//reached a leaf
			if(y[0]==0&&y[1]==0){
				found=true;
				return -1;
			}
			mask<<=1;
			if(y[0]==0)++mask;
			if(cnt==3){
				bool in=false;
				for(int i=0;i<6;++i){
					if(mask==check[i])in=true;
				}
				found=true;
				if(in)return (y[0]==0)?1:0;
				else return -1;
			}
			else{
				++cnt;
				return pv=(y[0]==0)?1:0;
			}
		}
		
		return pv=0;
	}
}

Compilation message

Catherine.cpp: In function 'int Move(std::vector<int>)':
Catherine.cpp:91:1: warning: control reaches end of non-void function [-Wreturn-type]
   91 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 40 ms 19532 KB Output is correct
2 Correct 3 ms 5240 KB Output is correct
3 Correct 42 ms 18940 KB Output is correct
4 Correct 51 ms 20656 KB Output is correct
5 Correct 48 ms 20652 KB Output is correct
6 Correct 36 ms 19228 KB Output is correct
7 Correct 38 ms 19392 KB Output is correct
8 Correct 51 ms 20016 KB Output is correct
9 Correct 61 ms 20124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 19532 KB Output is correct
2 Correct 3 ms 5240 KB Output is correct
3 Correct 42 ms 18940 KB Output is correct
4 Correct 51 ms 20656 KB Output is correct
5 Correct 48 ms 20652 KB Output is correct
6 Correct 36 ms 19228 KB Output is correct
7 Correct 38 ms 19392 KB Output is correct
8 Correct 51 ms 20016 KB Output is correct
9 Correct 61 ms 20124 KB Output is correct
10 Correct 34 ms 17412 KB Output is correct
11 Correct 33 ms 17380 KB Output is correct
12 Correct 36 ms 17504 KB Output is correct
13 Correct 39 ms 17428 KB Output is correct
14 Correct 44 ms 17628 KB Output is correct
15 Correct 41 ms 18404 KB Output is correct
16 Correct 43 ms 20184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 17104 KB Output is correct
2 Correct 3 ms 5212 KB Output is correct
3 Correct 33 ms 16732 KB Output is correct
4 Correct 46 ms 18536 KB Output is correct
5 Correct 61 ms 18448 KB Output is correct
6 Correct 35 ms 17192 KB Output is correct
7 Correct 39 ms 17220 KB Output is correct
8 Correct 56 ms 17760 KB Output is correct
9 Correct 47 ms 17692 KB Output is correct
10 Correct 43 ms 17612 KB Output is correct
11 Correct 39 ms 17572 KB Output is correct
12 Correct 40 ms 17416 KB Output is correct
13 Correct 40 ms 17524 KB Output is correct
14 Correct 41 ms 17728 KB Output is correct
15 Correct 47 ms 17908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 17104 KB Output is correct
2 Correct 3 ms 5212 KB Output is correct
3 Correct 33 ms 16732 KB Output is correct
4 Correct 46 ms 18536 KB Output is correct
5 Correct 61 ms 18448 KB Output is correct
6 Correct 35 ms 17192 KB Output is correct
7 Correct 39 ms 17220 KB Output is correct
8 Correct 56 ms 17760 KB Output is correct
9 Correct 47 ms 17692 KB Output is correct
10 Correct 43 ms 17612 KB Output is correct
11 Correct 39 ms 17572 KB Output is correct
12 Correct 40 ms 17416 KB Output is correct
13 Correct 40 ms 17524 KB Output is correct
14 Correct 41 ms 17728 KB Output is correct
15 Correct 47 ms 17908 KB Output is correct
16 Correct 34 ms 15584 KB Output is correct
17 Correct 36 ms 15556 KB Output is correct
18 Correct 38 ms 15412 KB Output is correct
19 Correct 32 ms 15560 KB Output is correct
20 Correct 43 ms 16052 KB Output is correct
21 Correct 38 ms 15800 KB Output is correct
22 Correct 44 ms 17960 KB Output is correct
23 Correct 35 ms 15748 KB Output is correct
24 Correct 52 ms 15776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5496 KB Output is correct
2 Correct 3 ms 5232 KB Output is correct
3 Correct 4 ms 5492 KB Output is correct
4 Correct 4 ms 5492 KB Output is correct
5 Correct 4 ms 5500 KB Output is correct
6 Correct 4 ms 5492 KB Output is correct
7 Correct 4 ms 5584 KB Output is correct
8 Correct 4 ms 5492 KB Output is correct
9 Correct 4 ms 5500 KB Output is correct
10 Correct 4 ms 5492 KB Output is correct
11 Correct 4 ms 5492 KB Output is correct
12 Correct 4 ms 5492 KB Output is correct
13 Correct 4 ms 5492 KB Output is correct
14 Correct 5 ms 5500 KB Output is correct
15 Correct 4 ms 5576 KB Output is correct
16 Correct 4 ms 5492 KB Output is correct
17 Correct 4 ms 5500 KB Output is correct
18 Correct 4 ms 5492 KB Output is correct
19 Correct 4 ms 5504 KB Output is correct
20 Correct 4 ms 5492 KB Output is correct
21 Correct 5 ms 5500 KB Output is correct
22 Correct 4 ms 5492 KB Output is correct
23 Correct 6 ms 5500 KB Output is correct
24 Correct 4 ms 5500 KB Output is correct
25 Correct 4 ms 5492 KB Output is correct
26 Correct 4 ms 5500 KB Output is correct
27 Correct 5 ms 5572 KB Output is correct
28 Correct 5 ms 5492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 15316 KB Output is correct
2 Correct 36 ms 16484 KB Output is correct
3 Correct 3 ms 5240 KB Output is correct
4 Correct 31 ms 15336 KB Output is correct
5 Correct 50 ms 18256 KB Output is correct
6 Correct 47 ms 18132 KB Output is correct
7 Correct 34 ms 17256 KB Output is correct
8 Correct 36 ms 17644 KB Output is correct
9 Correct 50 ms 18484 KB Output is correct
10 Correct 41 ms 18472 KB Output is correct
11 Correct 41 ms 18480 KB Output is correct
12 Correct 41 ms 18452 KB Output is correct
13 Correct 43 ms 18460 KB Output is correct
14 Correct 43 ms 18540 KB Output is correct
15 Correct 40 ms 18548 KB Output is correct
16 Correct 46 ms 18524 KB Output is correct
17 Correct 39 ms 18328 KB Output is correct
18 Correct 40 ms 18312 KB Output is correct
19 Correct 39 ms 18212 KB Output is correct
20 Correct 41 ms 18256 KB Output is correct
21 Correct 41 ms 18192 KB Output is correct
22 Correct 40 ms 18204 KB Output is correct
23 Correct 40 ms 15876 KB Output is correct
24 Correct 37 ms 15888 KB Output is correct
25 Correct 35 ms 16284 KB Output is correct
26 Correct 39 ms 16228 KB Output is correct
27 Correct 52 ms 17048 KB Output is correct
28 Correct 40 ms 17272 KB Output is correct
29 Correct 39 ms 17160 KB Output is correct
30 Correct 40 ms 17048 KB Output is correct
31 Correct 37 ms 15816 KB Output is correct
32 Correct 34 ms 15840 KB Output is correct
33 Correct 36 ms 16220 KB Output is correct
34 Correct 34 ms 16292 KB Output is correct
35 Correct 40 ms 17000 KB Output is correct
36 Correct 39 ms 17088 KB Output is correct
37 Correct 50 ms 17044 KB Output is correct
38 Correct 37 ms 17072 KB Output is correct
39 Correct 38 ms 17072 KB Output is correct
40 Correct 48 ms 16984 KB Output is correct
41 Correct 39 ms 17900 KB Output is correct
42 Correct 47 ms 17688 KB Output is correct
43 Correct 53 ms 17692 KB Output is correct
44 Correct 45 ms 17700 KB Output is correct
45 Correct 46 ms 17676 KB Output is correct
46 Correct 40 ms 17788 KB Output is correct
47 Correct 38 ms 16844 KB Output is correct
48 Correct 38 ms 16824 KB Output is correct
49 Correct 46 ms 16740 KB Output is correct
50 Correct 38 ms 16832 KB Output is correct
51 Correct 39 ms 16068 KB Output is correct
52 Correct 35 ms 16008 KB Output is correct
53 Correct 33 ms 16060 KB Output is correct
54 Correct 37 ms 15960 KB Output is correct
55 Correct 34 ms 16140 KB Output is correct
56 Correct 38 ms 16072 KB Output is correct
57 Correct 36 ms 16024 KB Output is correct
58 Correct 39 ms 15912 KB Output is correct
59 Correct 37 ms 16080 KB Output is correct
60 Correct 41 ms 16048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 15452 KB Output is correct
2 Correct 46 ms 16368 KB Output is correct
3 Correct 2 ms 5240 KB Output is correct
4 Correct 28 ms 15176 KB Output is correct
5 Correct 50 ms 18112 KB Output is correct
6 Correct 44 ms 18076 KB Output is correct
7 Correct 35 ms 17188 KB Output is correct
8 Correct 35 ms 17268 KB Output is correct
9 Correct 44 ms 18036 KB Output is correct
10 Correct 48 ms 18096 KB Output is correct
11 Correct 46 ms 18132 KB Output is correct
12 Correct 47 ms 18092 KB Output is correct
13 Correct 56 ms 18056 KB Output is correct
14 Correct 41 ms 18588 KB Output is correct
15 Correct 41 ms 18532 KB Output is correct
16 Correct 44 ms 18520 KB Output is correct
17 Correct 40 ms 18256 KB Output is correct
18 Correct 39 ms 18188 KB Output is correct
19 Correct 59 ms 18312 KB Output is correct
20 Correct 40 ms 18168 KB Output is correct
21 Correct 40 ms 18328 KB Output is correct
22 Correct 41 ms 18292 KB Output is correct
23 Correct 32 ms 15760 KB Output is correct
24 Correct 32 ms 15812 KB Output is correct
25 Correct 34 ms 16192 KB Output is correct
26 Correct 35 ms 16304 KB Output is correct
27 Correct 41 ms 17176 KB Output is correct
28 Correct 40 ms 17036 KB Output is correct
29 Correct 42 ms 17240 KB Output is correct
30 Correct 40 ms 17180 KB Output is correct
31 Correct 34 ms 15876 KB Output is correct
32 Correct 33 ms 15800 KB Output is correct
33 Correct 34 ms 16296 KB Output is correct
34 Correct 35 ms 16288 KB Output is correct
35 Correct 38 ms 17028 KB Output is correct
36 Correct 49 ms 17052 KB Output is correct
37 Correct 54 ms 17020 KB Output is correct
38 Correct 39 ms 17020 KB Output is correct
39 Correct 37 ms 17012 KB Output is correct
40 Correct 40 ms 16992 KB Output is correct
41 Correct 43 ms 17672 KB Output is correct
42 Correct 45 ms 17680 KB Output is correct
43 Correct 41 ms 17656 KB Output is correct
44 Correct 47 ms 17716 KB Output is correct
45 Correct 41 ms 17680 KB Output is correct
46 Correct 46 ms 17764 KB Output is correct
47 Correct 38 ms 16900 KB Output is correct
48 Correct 40 ms 16884 KB Output is correct
49 Correct 43 ms 16760 KB Output is correct
50 Correct 51 ms 16908 KB Output is correct
51 Correct 36 ms 16116 KB Output is correct
52 Correct 35 ms 16160 KB Output is correct
53 Correct 41 ms 16080 KB Output is correct
54 Correct 37 ms 16052 KB Output is correct
55 Correct 34 ms 16048 KB Output is correct
56 Correct 35 ms 16016 KB Output is correct
57 Correct 36 ms 16064 KB Output is correct
58 Correct 37 ms 16032 KB Output is correct
59 Correct 43 ms 15936 KB Output is correct
60 Correct 38 ms 16052 KB Output is correct