Submission #786559

# Submission time Handle Problem Language Result Execution time Memory
786559 2023-07-18T09:16:18 Z doowey Stray Cat (JOI20_stray) C++14
100 / 100
45 ms 17000 KB
#include "Anthony.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair

namespace {

const int N = (int)20010;
vector<pii> T[N];
vector<int> pattern = {1,1,0,1,0,0};
int dd[N];

}  // namespace


int n, m;
vector<int> idx;
int dep[N];

void make1(){
	queue<int> que;
	for(int i = 0 ; i < n; i ++ ){
		dep[i]=-1;
	}
	for(int i = 0 ; i < m ; i ++ ){
		idx[i]=-1;
	}
	dep[0]=0;
	que.push(0);
	int nd;
	while(!que.empty()){
		nd=que.front();
		que.pop();
		for(auto x : T[nd]){
			if(dep[x.fi] == -1){
				dep[x.fi]=(dep[nd]+1)%3;
				que.push(x.fi);
			}
			if(idx[x.se] == -1) idx[x.se]=dep[nd];
			
		}
	}
}

void dfs0(int u, int par, int bit){
	vector<pii> nex;
	for(auto x : T[u]){
		if(x.fi == par) continue;
		nex.push_back(x);
	}
	if(nex.size() == 1){
		if(dd[u]==-1){
			dd[u]=0;
			while(pattern[dd[u]] != bit) dd[u] ++ ;
		}
		dd[nex[0].fi] = (dd[u] + 1) % 6;
		idx[nex[0].se] = pattern[dd[nex[0].fi]];
		dfs0(nex[0].fi, u, pattern[(dd[u] + 1) % 6]);
	}
	else{
		for(auto x : nex){
			idx[x.se] = bit ^ 1;
			dfs0(x.fi, u, bit ^ 1);
		}
	}
}

void make2(){
	for(int i = 0 ; i < n; i ++ ){
		dd[i]=-1;
	}
	dfs0(0, -1, 0);
}

vector<int> Mark(int _n, int _m, int a, int b, vector<int> u, vector<int> v) {
	n = _n;
	m = _m;
	for(int i = 0 ; i < m ; i ++ ){
		T[u[i]].push_back(mp(v[i],i));
		T[v[i]].push_back(mp(u[i],i));
	}
	idx.resize(m);
	if(a >= 3) make1();
	else make2();
	return idx;
}
#include "Catherine.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair

namespace {

int A;
vector<int> trav;
int las;
bool know;
int step;

vector<int> pattern = {1, 1, 0, 1, 0, 0};

}  // namespace


void Init(int a, int b) {
	A = a;
	trav.clear();
	las = -1;
	know = false;
}

int move_3(vector<int> y){
	for(int d = 0; d < 3; d ++ ){
		if(y[d] > 0 && y[(d + 1) % 3] > 0) return d;
	}
	for(int d = 0; d < 3; d ++ ){
		if(y[d] > 0) return d;
	}
	return -1;
}

int move_2(vector<int> y){
	step ++ ;
	vector<int> g = y;
	if(las != -1) g[las] ++ ;
	
	int pick = -1;
	if(g[0] + g[1] != 2){
		
		know = true;
		
		trav.clear();
		if(g[0] == 1) pick = 0;
		else pick = 1;
		las = pick;
	}
	else{
		if(know){
			if(y[0] == 1) pick = 0;
			else pick = 1;
			las=pick;
		}
		else{
			if(trav.empty()){
				for(int d = 0; d < 2; d ++ ){
					for(int p = 0 ; p < y[d]; p ++ ){
						trav.push_back(d);
						pick=d;
						las=d;
					}
				}
			}
			else if(trav.size() <= 3){
				if(y[0]==1) pick=0;
				else pick=1;
				las = pick;
				trav.push_back(pick);
			}
			else{
				if(y[0] == 1) trav.push_back(0);
				else trav.push_back(1);
				bool rev = false;
				for(int i = 0 ; i < 6 ; i ++ ){
					vector<int> g;
					for(int j = 0 ; j < trav.size(); j ++ ){
						g.push_back(pattern[(i + j) % 6]);
					}
					if(g == trav) rev = true;
				}
				if(rev == true){
					pick = -1;
					trav.pop_back();
					las = trav.back();
				}
				else{
					if(y[0] == 1) pick = 0;
					else pick = 1;
					las = pick;
				}
				trav.clear();
				know=true;
			}
		}
	}
	if(pick == -1 || y[pick] == 0) pick = -1;
	return pick;
}

int Move(std::vector<int> y) {
   if(A >= 3) return move_3(y);
   else{
	   return move_2(y);
   }
   return -1;
}

Compilation message

Catherine.cpp: In function 'int move_2(std::vector<int>)':
Catherine.cpp:86:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |      for(int j = 0 ; j < trav.size(); j ++ ){
      |                      ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 28 ms 15920 KB Output is correct
2 Correct 1 ms 1028 KB Output is correct
3 Correct 26 ms 15104 KB Output is correct
4 Correct 39 ms 17000 KB Output is correct
5 Correct 34 ms 16888 KB Output is correct
6 Correct 26 ms 15648 KB Output is correct
7 Correct 26 ms 15756 KB Output is correct
8 Correct 32 ms 16436 KB Output is correct
9 Correct 32 ms 16456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 15920 KB Output is correct
2 Correct 1 ms 1028 KB Output is correct
3 Correct 26 ms 15104 KB Output is correct
4 Correct 39 ms 17000 KB Output is correct
5 Correct 34 ms 16888 KB Output is correct
6 Correct 26 ms 15648 KB Output is correct
7 Correct 26 ms 15756 KB Output is correct
8 Correct 32 ms 16436 KB Output is correct
9 Correct 32 ms 16456 KB Output is correct
10 Correct 25 ms 13916 KB Output is correct
11 Correct 25 ms 13888 KB Output is correct
12 Correct 25 ms 13876 KB Output is correct
13 Correct 34 ms 13884 KB Output is correct
14 Correct 27 ms 14012 KB Output is correct
15 Correct 27 ms 14412 KB Output is correct
16 Correct 30 ms 16500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 13444 KB Output is correct
2 Correct 1 ms 1036 KB Output is correct
3 Correct 25 ms 13036 KB Output is correct
4 Correct 34 ms 14796 KB Output is correct
5 Correct 34 ms 14804 KB Output is correct
6 Correct 27 ms 13548 KB Output is correct
7 Correct 26 ms 13624 KB Output is correct
8 Correct 30 ms 14184 KB Output is correct
9 Correct 30 ms 14172 KB Output is correct
10 Correct 30 ms 13876 KB Output is correct
11 Correct 39 ms 14040 KB Output is correct
12 Correct 27 ms 13952 KB Output is correct
13 Correct 32 ms 13908 KB Output is correct
14 Correct 31 ms 14196 KB Output is correct
15 Correct 31 ms 14260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 13444 KB Output is correct
2 Correct 1 ms 1036 KB Output is correct
3 Correct 25 ms 13036 KB Output is correct
4 Correct 34 ms 14796 KB Output is correct
5 Correct 34 ms 14804 KB Output is correct
6 Correct 27 ms 13548 KB Output is correct
7 Correct 26 ms 13624 KB Output is correct
8 Correct 30 ms 14184 KB Output is correct
9 Correct 30 ms 14172 KB Output is correct
10 Correct 30 ms 13876 KB Output is correct
11 Correct 39 ms 14040 KB Output is correct
12 Correct 27 ms 13952 KB Output is correct
13 Correct 32 ms 13908 KB Output is correct
14 Correct 31 ms 14196 KB Output is correct
15 Correct 31 ms 14260 KB Output is correct
16 Correct 23 ms 11948 KB Output is correct
17 Correct 23 ms 11900 KB Output is correct
18 Correct 33 ms 11812 KB Output is correct
19 Correct 24 ms 11896 KB Output is correct
20 Correct 27 ms 12568 KB Output is correct
21 Correct 25 ms 12384 KB Output is correct
22 Correct 33 ms 14300 KB Output is correct
23 Correct 30 ms 11972 KB Output is correct
24 Correct 27 ms 11952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1288 KB Output is correct
2 Correct 1 ms 1092 KB Output is correct
3 Correct 2 ms 1332 KB Output is correct
4 Correct 2 ms 1416 KB Output is correct
5 Correct 2 ms 1348 KB Output is correct
6 Correct 2 ms 1424 KB Output is correct
7 Correct 2 ms 1424 KB Output is correct
8 Correct 2 ms 1348 KB Output is correct
9 Correct 2 ms 1412 KB Output is correct
10 Correct 2 ms 1420 KB Output is correct
11 Correct 2 ms 1412 KB Output is correct
12 Correct 2 ms 1416 KB Output is correct
13 Correct 2 ms 1444 KB Output is correct
14 Correct 2 ms 1412 KB Output is correct
15 Correct 2 ms 1416 KB Output is correct
16 Correct 2 ms 1296 KB Output is correct
17 Correct 2 ms 1288 KB Output is correct
18 Correct 2 ms 1344 KB Output is correct
19 Correct 2 ms 1296 KB Output is correct
20 Correct 2 ms 1288 KB Output is correct
21 Correct 2 ms 1296 KB Output is correct
22 Correct 3 ms 1296 KB Output is correct
23 Correct 2 ms 1288 KB Output is correct
24 Correct 2 ms 1296 KB Output is correct
25 Correct 2 ms 1296 KB Output is correct
26 Correct 2 ms 1296 KB Output is correct
27 Correct 2 ms 1288 KB Output is correct
28 Correct 2 ms 1288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 11736 KB Output is correct
2 Correct 29 ms 13628 KB Output is correct
3 Correct 1 ms 1036 KB Output is correct
4 Correct 22 ms 11472 KB Output is correct
5 Correct 32 ms 15892 KB Output is correct
6 Correct 32 ms 15848 KB Output is correct
7 Correct 32 ms 14944 KB Output is correct
8 Correct 28 ms 14980 KB Output is correct
9 Correct 43 ms 15852 KB Output is correct
10 Correct 32 ms 15808 KB Output is correct
11 Correct 38 ms 15804 KB Output is correct
12 Correct 32 ms 15932 KB Output is correct
13 Correct 33 ms 15832 KB Output is correct
14 Correct 32 ms 15920 KB Output is correct
15 Correct 32 ms 15820 KB Output is correct
16 Correct 34 ms 15860 KB Output is correct
17 Correct 32 ms 15656 KB Output is correct
18 Correct 30 ms 15544 KB Output is correct
19 Correct 30 ms 15556 KB Output is correct
20 Correct 33 ms 15500 KB Output is correct
21 Correct 30 ms 15560 KB Output is correct
22 Correct 30 ms 15580 KB Output is correct
23 Correct 26 ms 11768 KB Output is correct
24 Correct 34 ms 11808 KB Output is correct
25 Correct 27 ms 12448 KB Output is correct
26 Correct 29 ms 12400 KB Output is correct
27 Correct 27 ms 13836 KB Output is correct
28 Correct 27 ms 13772 KB Output is correct
29 Correct 30 ms 13776 KB Output is correct
30 Correct 27 ms 13872 KB Output is correct
31 Correct 25 ms 11656 KB Output is correct
32 Correct 27 ms 11644 KB Output is correct
33 Correct 31 ms 12328 KB Output is correct
34 Correct 25 ms 12292 KB Output is correct
35 Correct 28 ms 13460 KB Output is correct
36 Correct 28 ms 13452 KB Output is correct
37 Correct 27 ms 13588 KB Output is correct
38 Correct 27 ms 13580 KB Output is correct
39 Correct 28 ms 13528 KB Output is correct
40 Correct 27 ms 13508 KB Output is correct
41 Correct 30 ms 14648 KB Output is correct
42 Correct 32 ms 14580 KB Output is correct
43 Correct 31 ms 14636 KB Output is correct
44 Correct 30 ms 14648 KB Output is correct
45 Correct 30 ms 14480 KB Output is correct
46 Correct 30 ms 14600 KB Output is correct
47 Correct 27 ms 13372 KB Output is correct
48 Correct 27 ms 13252 KB Output is correct
49 Correct 32 ms 13132 KB Output is correct
50 Correct 30 ms 13248 KB Output is correct
51 Correct 26 ms 11840 KB Output is correct
52 Correct 24 ms 11908 KB Output is correct
53 Correct 25 ms 11832 KB Output is correct
54 Correct 25 ms 11840 KB Output is correct
55 Correct 30 ms 11884 KB Output is correct
56 Correct 26 ms 11860 KB Output is correct
57 Correct 27 ms 11836 KB Output is correct
58 Correct 30 ms 11756 KB Output is correct
59 Correct 25 ms 11968 KB Output is correct
60 Correct 24 ms 11976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 11688 KB Output is correct
2 Correct 27 ms 13500 KB Output is correct
3 Correct 1 ms 1096 KB Output is correct
4 Correct 20 ms 11600 KB Output is correct
5 Correct 43 ms 15792 KB Output is correct
6 Correct 35 ms 15748 KB Output is correct
7 Correct 39 ms 15216 KB Output is correct
8 Correct 32 ms 14852 KB Output is correct
9 Correct 44 ms 15700 KB Output is correct
10 Correct 32 ms 15728 KB Output is correct
11 Correct 35 ms 15876 KB Output is correct
12 Correct 33 ms 15920 KB Output is correct
13 Correct 33 ms 15772 KB Output is correct
14 Correct 34 ms 15932 KB Output is correct
15 Correct 33 ms 15872 KB Output is correct
16 Correct 34 ms 15776 KB Output is correct
17 Correct 41 ms 15524 KB Output is correct
18 Correct 34 ms 15584 KB Output is correct
19 Correct 33 ms 15496 KB Output is correct
20 Correct 45 ms 15392 KB Output is correct
21 Correct 32 ms 15476 KB Output is correct
22 Correct 31 ms 15432 KB Output is correct
23 Correct 27 ms 11664 KB Output is correct
24 Correct 30 ms 11644 KB Output is correct
25 Correct 28 ms 12300 KB Output is correct
26 Correct 31 ms 12396 KB Output is correct
27 Correct 34 ms 13708 KB Output is correct
28 Correct 30 ms 13780 KB Output is correct
29 Correct 28 ms 13772 KB Output is correct
30 Correct 31 ms 13692 KB Output is correct
31 Correct 26 ms 11736 KB Output is correct
32 Correct 26 ms 11636 KB Output is correct
33 Correct 33 ms 12436 KB Output is correct
34 Correct 28 ms 12312 KB Output is correct
35 Correct 30 ms 13464 KB Output is correct
36 Correct 28 ms 13560 KB Output is correct
37 Correct 28 ms 13592 KB Output is correct
38 Correct 36 ms 13512 KB Output is correct
39 Correct 31 ms 13488 KB Output is correct
40 Correct 31 ms 13512 KB Output is correct
41 Correct 33 ms 14520 KB Output is correct
42 Correct 28 ms 14640 KB Output is correct
43 Correct 30 ms 14616 KB Output is correct
44 Correct 39 ms 14624 KB Output is correct
45 Correct 30 ms 14512 KB Output is correct
46 Correct 32 ms 14548 KB Output is correct
47 Correct 28 ms 13492 KB Output is correct
48 Correct 31 ms 13348 KB Output is correct
49 Correct 31 ms 13136 KB Output is correct
50 Correct 27 ms 13364 KB Output is correct
51 Correct 25 ms 11752 KB Output is correct
52 Correct 25 ms 11840 KB Output is correct
53 Correct 25 ms 11808 KB Output is correct
54 Correct 26 ms 11856 KB Output is correct
55 Correct 26 ms 11820 KB Output is correct
56 Correct 28 ms 11852 KB Output is correct
57 Correct 31 ms 11748 KB Output is correct
58 Correct 25 ms 11760 KB Output is correct
59 Correct 25 ms 11888 KB Output is correct
60 Correct 25 ms 11972 KB Output is correct