Submission #426842

# Submission time Handle Problem Language Result Execution time Memory
426842 2021-06-14T10:24:49 Z amunduzbaev Stray Cat (JOI20_stray) C++14
100 / 100
90 ms 21348 KB
#include"bits/stdc++.h"
#include"Anthony.h"
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
 
 
namespace sol1{
	
	vector<int> a = {0, 0, 1, 0, 1, 1};
 
	vector<pair<int,int>> e[100000];
	
	vector<int> ret;
	
	void dfs(int n, int p, int b, int k){
		//cout << n << " " << p << " " << b << " " << k << endl;
		rep(i, e[n].size()){
			if(e[n][i].first == p) continue;
			if(e[n].size() >= 3){
				if(b == 0){
					ret[e[n][i].second] = 1;
					dfs(e[n][i].first, n, 1, 2);
				}
				else{
					ret[e[n][i].second] = 0;
					dfs(e[n][i].first, n, 0, 1);
				}
			}
			if(e[n].size() == 2){
				ret[e[n][i].second] = a[(k+1)%6];
				dfs(e[n][i].first, n, a[(k+1)%6], k+1);
			}
		}
	}
	
	vector<int> Mark1(int N, int M, int A, int B, vector<int> U, vector<int> V){
		for(int i=0; i<M; i++){
			e[U[i]].push_back({V[i], i});
			e[V[i]].push_back({U[i], i});
			ret.push_back(-1);
		}
		e[0].pb({-1,-1});
		
		dfs(0, -1, 1, 0);
		rep(i, M){
			//cout << i << " " << ret[i] << endl;
		}
		return ret;
	}
	
}  // namespace
 
 
namespace sol2{
 
	vector<pair<int,int>> e[100000];
	int cost[100000];
	queue<int> que;
	vector<int> ret;
	
	vector<int> Mark2(int N, int M, int A, int B, vector<int> U, vector<int> V){
		for(int i=0; i<M; i++){
			e[U[i]].push_back({V[i], i});
			e[V[i]].push_back({U[i], i});
			ret.push_back(3);
		}
		
		for(int i=0; i<N; i++){
			cost[i] = INT_MAX;
		}
		cost[0] = 0;
		que.push(0);
		while(!que.empty()){
			int n = que.front();
			que.pop();
			for(int i=0; i<e[n].size(); i++){
				if(cost[e[n][i].first] > cost[n]+1){
					cost[e[n][i].first] = cost[n]+1;
					que.push(e[n][i].first);
				}
			}
		}
		
		for(int i=0; i<M; i++){
			if(cost[U[i]]+1 == cost[V[i]]) ret[i] = cost[U[i]] % 3;
			if(cost[U[i]] == cost[V[i]]+1) ret[i] = cost[V[i]] % 3;
			if(cost[U[i]] == cost[V[i]]) ret[i] = cost[U[i]] % 3;
		}
		
		return ret;
	}
 
}  // namespace
 
vector<int> Mark(int N, int M, int A, int B, vector<int> U, vector<int> V){
	if(A == 2) return sol1::Mark1(N, M, A, B, U, V);
	return sol2::Mark2(N, M, A, B, U, V);
}
#include"bits/stdc++.h"
#include"Catherine.h"
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
 
 
namespace sola{
	
	vector<int> a = {0, 0, 1, 0, 1, 1};
 
	int A, B;
	
	bool flg = false;
	vector<int> st;
	int b = -1;
	
	int Move1(vector<int> y){
		//cout <<  b << " " << flg << " " << y[0] << " " << y[1] << endl;
		if(flg){
			// -o-
			if(y[0]+y[1]+1 == 2){
				if(y[0] == 0) return b = 1;
				if(y[1] == 0) return b = 0;
			}
			// -o<
			if(y[0]+y[1]+1 > 2){
				return b = b^1;
			}
			assert(false);
		}
		
		// -o<
		if(b != -1) y[b]++;
		if(y[0]+y[1] > 2){
			flg = true;
			if(y[0] == 1){
				if(b == 0) return -1;
				return b = 0;
			}
			if(y[1] == 1){
				if(b == 1) return -1;
				return b = 1;
			}
		}
		// -o
		if(y[0] == 0 && y[1] == 1){
			flg = true;
			if(b == -1) return b = 1;
			b = 1;
			return -1;
		}
		if(y[1] == 0 && y[0] == 1){
			flg = true;
			if(b == -1) return b = 0;
			b = 0;
			return -1;
		}
		// -o-
		if(b != -1) y[b]--;
		if(b == -1){
			if(y[0] == 2){
				st.pb(0);
				st.pb(0);
				return b = 0;
			}
			if(y[1] == 2){
				st.pb(1);
				st.pb(1);
				return b = 1;
			}
			st.pb(0);
			st.pb(1);
			return b = 1;
		}
		else{
			if(y[0] == 1) st.pb(0);
			if(y[1] == 1) st.pb(1);
			if(st.size() == 5){
				flg = true;
				bool ok = true;
				rep(j, 6){
					bool same = true;
					rep(k, 5){
						same = same & (st[k] == a[(j+k)%6]);
					}
					if(same) ok = false;
				}
				//if(ok) cout << "ok" << endl;
				//else cout << "ng" << endl;
				if(ok) return b = st[4];
				else{
					b = st[3];
					//cout << "return -1" << endl;
					return -1;
				}
			}
			else{
				return b = st.back();
			}
		}
	}
 
}  // namespace
 
namespace solb{
	
	int Move2(vector<int> y){
		if(y[0] > 0 && y[1] >= 0 && y[2] == 0) return 0;
		if(y[1] > 0 && y[2] >= 0 && y[0] == 0) return 1;
		if(y[2] > 0 && y[0] >= 0 && y[1] == 0) return 2;
	}
	
}  // namespace
 
void Init(int A, int B){
	sola::A = A;
	sola::B = B;
}
 
int Move(vector<int> y){
	if(sola::A == 2) return sola::Move1(y);
	return solb::Move2(y);
}

Compilation message

Anthony.cpp: In function 'void sol1::dfs(int, int, int, int)':
Anthony.cpp:9:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    9 | #define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
      |                           ^
Anthony.cpp:22:3: note: in expansion of macro 'rep'
   22 |   rep(i, e[n].size()){
      |   ^~~
Anthony.cpp: In function 'std::vector<int> sol1::Mark1(int, int, int, int, std::vector<int>, std::vector<int>)':
Anthony.cpp:9:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    9 | #define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
      |                           ^
Anthony.cpp:50:3: note: in expansion of macro 'rep'
   50 |   rep(i, M){
      |   ^~~
Anthony.cpp: In function 'std::vector<int> sol2::Mark2(int, int, int, int, std::vector<int>, std::vector<int>)':
Anthony.cpp:81:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |    for(int i=0; i<e[n].size(); i++){
      |                 ~^~~~~~~~~~~~

Catherine.cpp: In function 'int sola::Move1(std::vector<int>)':
Catherine.cpp:9:27: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
    9 | #define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
      |                           ^
Catherine.cpp:86:5: note: in expansion of macro 'rep'
   86 |     rep(j, 6){
      |     ^~~
Catherine.cpp:9:27: warning: unnecessary parentheses in declaration of 'k' [-Wparentheses]
    9 | #define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
      |                           ^
Catherine.cpp:88:6: note: in expansion of macro 'rep'
   88 |      rep(k, 5){
      |      ^~~
Catherine.cpp: In function 'int solb::Move2(std::vector<int>)':
Catherine.cpp:116:2: warning: control reaches end of non-void function [-Wreturn-type]
  116 |  }
      |  ^
# Verdict Execution time Memory Grader output
1 Correct 52 ms 20260 KB Output is correct
2 Correct 4 ms 5304 KB Output is correct
3 Correct 41 ms 19692 KB Output is correct
4 Correct 68 ms 21348 KB Output is correct
5 Correct 65 ms 21332 KB Output is correct
6 Correct 50 ms 20148 KB Output is correct
7 Correct 51 ms 19992 KB Output is correct
8 Correct 58 ms 20716 KB Output is correct
9 Correct 59 ms 20820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 20260 KB Output is correct
2 Correct 4 ms 5304 KB Output is correct
3 Correct 41 ms 19692 KB Output is correct
4 Correct 68 ms 21348 KB Output is correct
5 Correct 65 ms 21332 KB Output is correct
6 Correct 50 ms 20148 KB Output is correct
7 Correct 51 ms 19992 KB Output is correct
8 Correct 58 ms 20716 KB Output is correct
9 Correct 59 ms 20820 KB Output is correct
10 Correct 49 ms 18004 KB Output is correct
11 Correct 45 ms 18284 KB Output is correct
12 Correct 43 ms 18208 KB Output is correct
13 Correct 59 ms 18100 KB Output is correct
14 Correct 57 ms 18400 KB Output is correct
15 Correct 53 ms 18704 KB Output is correct
16 Correct 59 ms 20980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 17888 KB Output is correct
2 Correct 4 ms 5288 KB Output is correct
3 Correct 39 ms 17364 KB Output is correct
4 Correct 72 ms 19104 KB Output is correct
5 Correct 70 ms 19072 KB Output is correct
6 Correct 50 ms 17808 KB Output is correct
7 Correct 56 ms 17820 KB Output is correct
8 Correct 72 ms 18436 KB Output is correct
9 Correct 54 ms 18412 KB Output is correct
10 Correct 47 ms 18368 KB Output is correct
11 Correct 51 ms 18212 KB Output is correct
12 Correct 69 ms 18140 KB Output is correct
13 Correct 59 ms 18144 KB Output is correct
14 Correct 52 ms 18472 KB Output is correct
15 Correct 72 ms 18544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 17888 KB Output is correct
2 Correct 4 ms 5288 KB Output is correct
3 Correct 39 ms 17364 KB Output is correct
4 Correct 72 ms 19104 KB Output is correct
5 Correct 70 ms 19072 KB Output is correct
6 Correct 50 ms 17808 KB Output is correct
7 Correct 56 ms 17820 KB Output is correct
8 Correct 72 ms 18436 KB Output is correct
9 Correct 54 ms 18412 KB Output is correct
10 Correct 47 ms 18368 KB Output is correct
11 Correct 51 ms 18212 KB Output is correct
12 Correct 69 ms 18140 KB Output is correct
13 Correct 59 ms 18144 KB Output is correct
14 Correct 52 ms 18472 KB Output is correct
15 Correct 72 ms 18544 KB Output is correct
16 Correct 57 ms 16252 KB Output is correct
17 Correct 43 ms 16284 KB Output is correct
18 Correct 44 ms 16212 KB Output is correct
19 Correct 47 ms 16268 KB Output is correct
20 Correct 53 ms 16888 KB Output is correct
21 Correct 59 ms 16672 KB Output is correct
22 Correct 56 ms 18724 KB Output is correct
23 Correct 42 ms 16364 KB Output is correct
24 Correct 45 ms 16404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 5548 KB Output is correct
2 Correct 5 ms 5236 KB Output is correct
3 Correct 5 ms 5496 KB Output is correct
4 Correct 5 ms 5624 KB Output is correct
5 Correct 5 ms 5624 KB Output is correct
6 Correct 5 ms 5624 KB Output is correct
7 Correct 5 ms 5616 KB Output is correct
8 Correct 5 ms 5620 KB Output is correct
9 Correct 6 ms 5556 KB Output is correct
10 Correct 5 ms 5624 KB Output is correct
11 Correct 5 ms 5620 KB Output is correct
12 Correct 5 ms 5496 KB Output is correct
13 Correct 5 ms 5496 KB Output is correct
14 Correct 5 ms 5624 KB Output is correct
15 Correct 5 ms 5516 KB Output is correct
16 Correct 5 ms 5556 KB Output is correct
17 Correct 5 ms 5476 KB Output is correct
18 Correct 6 ms 5556 KB Output is correct
19 Correct 5 ms 5556 KB Output is correct
20 Correct 5 ms 5688 KB Output is correct
21 Correct 5 ms 5544 KB Output is correct
22 Correct 5 ms 5496 KB Output is correct
23 Correct 5 ms 5532 KB Output is correct
24 Correct 5 ms 5556 KB Output is correct
25 Correct 5 ms 5580 KB Output is correct
26 Correct 4 ms 5496 KB Output is correct
27 Correct 5 ms 5492 KB Output is correct
28 Correct 5 ms 5500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 15992 KB Output is correct
2 Correct 49 ms 17248 KB Output is correct
3 Correct 4 ms 5236 KB Output is correct
4 Correct 38 ms 15716 KB Output is correct
5 Correct 65 ms 18664 KB Output is correct
6 Correct 74 ms 18716 KB Output is correct
7 Correct 56 ms 17804 KB Output is correct
8 Correct 47 ms 17744 KB Output is correct
9 Correct 66 ms 18760 KB Output is correct
10 Correct 71 ms 18612 KB Output is correct
11 Correct 55 ms 18648 KB Output is correct
12 Correct 52 ms 18628 KB Output is correct
13 Correct 59 ms 18640 KB Output is correct
14 Correct 62 ms 18648 KB Output is correct
15 Correct 65 ms 18764 KB Output is correct
16 Correct 66 ms 18644 KB Output is correct
17 Correct 53 ms 18376 KB Output is correct
18 Correct 53 ms 18420 KB Output is correct
19 Correct 64 ms 18480 KB Output is correct
20 Correct 52 ms 18376 KB Output is correct
21 Correct 51 ms 18408 KB Output is correct
22 Correct 60 ms 18392 KB Output is correct
23 Correct 45 ms 16064 KB Output is correct
24 Correct 50 ms 15984 KB Output is correct
25 Correct 51 ms 16360 KB Output is correct
26 Correct 49 ms 16440 KB Output is correct
27 Correct 60 ms 17392 KB Output is correct
28 Correct 62 ms 17384 KB Output is correct
29 Correct 50 ms 17376 KB Output is correct
30 Correct 51 ms 17400 KB Output is correct
31 Correct 50 ms 16060 KB Output is correct
32 Correct 54 ms 15960 KB Output is correct
33 Correct 68 ms 16400 KB Output is correct
34 Correct 45 ms 16472 KB Output is correct
35 Correct 62 ms 17292 KB Output is correct
36 Correct 53 ms 17172 KB Output is correct
37 Correct 49 ms 17308 KB Output is correct
38 Correct 53 ms 17260 KB Output is correct
39 Correct 65 ms 17240 KB Output is correct
40 Correct 64 ms 17240 KB Output is correct
41 Correct 62 ms 17992 KB Output is correct
42 Correct 62 ms 17752 KB Output is correct
43 Correct 57 ms 17836 KB Output is correct
44 Correct 63 ms 17892 KB Output is correct
45 Correct 57 ms 17896 KB Output is correct
46 Correct 64 ms 17880 KB Output is correct
47 Correct 60 ms 16964 KB Output is correct
48 Correct 49 ms 17056 KB Output is correct
49 Correct 56 ms 16936 KB Output is correct
50 Correct 52 ms 17144 KB Output is correct
51 Correct 46 ms 16168 KB Output is correct
52 Correct 42 ms 16352 KB Output is correct
53 Correct 46 ms 16248 KB Output is correct
54 Correct 51 ms 16144 KB Output is correct
55 Correct 51 ms 16348 KB Output is correct
56 Correct 52 ms 16312 KB Output is correct
57 Correct 44 ms 16316 KB Output is correct
58 Correct 44 ms 16368 KB Output is correct
59 Correct 53 ms 16160 KB Output is correct
60 Correct 44 ms 16236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 16080 KB Output is correct
2 Correct 46 ms 17160 KB Output is correct
3 Correct 4 ms 5296 KB Output is correct
4 Correct 38 ms 15656 KB Output is correct
5 Correct 90 ms 18692 KB Output is correct
6 Correct 72 ms 18620 KB Output is correct
7 Correct 56 ms 17764 KB Output is correct
8 Correct 61 ms 17764 KB Output is correct
9 Correct 61 ms 18604 KB Output is correct
10 Correct 59 ms 18612 KB Output is correct
11 Correct 77 ms 18716 KB Output is correct
12 Correct 66 ms 18716 KB Output is correct
13 Correct 90 ms 18688 KB Output is correct
14 Correct 61 ms 18688 KB Output is correct
15 Correct 57 ms 18612 KB Output is correct
16 Correct 63 ms 18716 KB Output is correct
17 Correct 62 ms 18384 KB Output is correct
18 Correct 59 ms 18420 KB Output is correct
19 Correct 56 ms 18336 KB Output is correct
20 Correct 56 ms 18396 KB Output is correct
21 Correct 66 ms 18332 KB Output is correct
22 Correct 66 ms 18344 KB Output is correct
23 Correct 66 ms 16044 KB Output is correct
24 Correct 48 ms 16020 KB Output is correct
25 Correct 54 ms 16456 KB Output is correct
26 Correct 50 ms 16356 KB Output is correct
27 Correct 77 ms 17364 KB Output is correct
28 Correct 68 ms 17352 KB Output is correct
29 Correct 54 ms 17360 KB Output is correct
30 Correct 52 ms 17408 KB Output is correct
31 Correct 51 ms 15996 KB Output is correct
32 Correct 46 ms 16024 KB Output is correct
33 Correct 46 ms 16492 KB Output is correct
34 Correct 47 ms 16496 KB Output is correct
35 Correct 61 ms 17236 KB Output is correct
36 Correct 53 ms 17208 KB Output is correct
37 Correct 50 ms 17300 KB Output is correct
38 Correct 49 ms 17176 KB Output is correct
39 Correct 50 ms 17224 KB Output is correct
40 Correct 59 ms 17260 KB Output is correct
41 Correct 66 ms 17864 KB Output is correct
42 Correct 54 ms 17764 KB Output is correct
43 Correct 50 ms 17888 KB Output is correct
44 Correct 54 ms 17928 KB Output is correct
45 Correct 52 ms 17964 KB Output is correct
46 Correct 53 ms 17940 KB Output is correct
47 Correct 48 ms 17100 KB Output is correct
48 Correct 49 ms 16992 KB Output is correct
49 Correct 51 ms 17020 KB Output is correct
50 Correct 50 ms 17156 KB Output is correct
51 Correct 45 ms 16244 KB Output is correct
52 Correct 43 ms 16304 KB Output is correct
53 Correct 48 ms 16340 KB Output is correct
54 Correct 46 ms 16292 KB Output is correct
55 Correct 45 ms 16340 KB Output is correct
56 Correct 49 ms 16356 KB Output is correct
57 Correct 44 ms 16284 KB Output is correct
58 Correct 43 ms 16428 KB Output is correct
59 Correct 44 ms 16140 KB Output is correct
60 Correct 50 ms 16220 KB Output is correct