답안 #427863

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
427863 2021-06-15T02:40:53 Z amunduzbaev 길고양이 (JOI20_stray) C++14
100 / 100
76 ms 17976 KB
#include "Anthony.h"
#include "bits/stdc++.h"
using namespace std;
 
#define ff first
#define ss second
#define pb push_back
#define sz(x) (int)x.size()
 
const int N = 2e4+5;
 
namespace sol1{
	
	vector<int> res;
	vector<int> patt = {0, 1, 1, 0, 0, 1};
	vector<pair<int, int>> edges[N];
	
	
	void dfs(int u, int p = -1, int cur = 0, int in = 0){
		for(auto x : edges[u]){
			if(x.ff == p) continue;
			if(sz(edges[u]) == 2){
				res[x.ss] = patt[in];
				dfs(x.ff, u, res[x.ss], (in + 1) % 6);
			} else {
				res[x.ss] = cur ^ 1;
				if(cur) dfs(x.ff, u, cur ^ 1, 1);
				else dfs(x.ff, u, cur ^ 1, 2);
			}
		}
	}
	
	vector<int> Mark1(int n, int m, int a, int b, vector<int> u, vector<int> v){
		res.resize(m);
		for(int i=0;i<m;i++){
			int a = u[i] + 1, b = v[i] + 1;
			edges[a].pb({b, i}), edges[b].pb({a, i});
			res[i] = -1;
		} 
		
		edges[1].pb({-1, -1});
		dfs(1);
		
		//~ for(int i=0;i<m;i++) cout<<res[i]<<" ";
		//~ cout<<"\n";
		
		return res;
	}
}
 
namespace sol2{
	template<class T> bool umin(T& a, const T b) { if(a > b) { a = b; return 1; }  return 0; }
	template<class T> bool umax(T& a, const T b) { if(a < b) { a = b; return 1; }  return 0; }
	const int N = 2e4+5;
	vector<int> edges[N], res, dd;
	//~ const int inf = ;
	vector<int> Mark2(int n, int m, int a, int b, vector<int> u, vector<int> v){
		res.resize(m);
		for(int i=0;i<m;i++){
			int a = u[i] + 1, b = v[i] + 1; cin>>a>>b;
			edges[a].pb(b), edges[b].pb(a);
		} queue<int> qq;
		qq.push(1);
		dd.assign(n+1, 1e9+7); dd[1] = 0;
		while(!qq.empty()){
			int u = qq.front(); qq.pop();
			for(auto x : edges[u]){
				if(umin(dd[x], dd[u] + 1)) qq.push(x);
			}
		}
		for(int i=0;i<m;i++){
			int a = u[i] + 1, b = v[i] + 1;
			res[i] = min(dd[a], dd[b]) % 3;
		} return res;
	}
}
 
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);
	} else {
		return sol2::Mark2(n, m, a, b, u, v);
	}
}
#include "Catherine.h"
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define sz(x) (int)x.size()
 
vector<int> path;
int a;
 
void Init(int a, int b) { ::a = a; }
 
namespace sol1{
	vector<int> ppat = {0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1};
	int ok = 0, last = -1;
	vector<int> path;
	
	int Move(vector<int> y){
		if(ok){
			assert(~last);
			if(y[0] + y[1] + 1 > 2) return last ^= 1;
			if(y[0] == 0) return last = 1;
			if(y[1] == 0) return last = 0;
			assert(0); 
		}
		
		if(y[0] + y[1] + (last != -1) > 2){
			ok = 1;
			if(~last){
				if(min(y[0], y[1]) == 0) return -1;
				if(min(y[0], y[1]) == 1) return last ^= 1;
				assert(0);
			} else {
				if(y[0] == 1) return last = 0;
				if(y[1] == 1) return last = 1;
				assert(0);
			}
		} 
		
		if(y[0] + y[1] + (last != -1) == 1){
			ok = 1;
			if(y[0] == 1) return last = 0;
			if(y[1] == 1) return last = 1;
			return -1;
		}
		
		if(last == -1){
			if(y[0] == 2) { path.pb(0), path.pb(0); return last = 0; }
			else if(y[1] == 2) { path.pb(1), path.pb(1); return last = 1; }
			else { path.pb(0), path.pb(1); return last = 1; }
		} 
		else {
			if(y[0] == 1) last = 0, path.pb(0);
			if(y[1] == 1) last = 1, path.pb(1);
			
			if(sz(path) == 5){ ok = 1; 
				for(int i=0;i+5<=sz(ppat);i++){
					int l = i, r = i + 5 - 1, okk = 1;
					for(int j=l;j<=r;j++) okk &= (ppat[j] == path[j-i]);
					if(okk) return -1;
				} if(y[0]) return last = 0;
				else return last = 1;
			} else return last;
		}
	} 
}
 
namespace sol2{
	int Move(vector<int> y){
		 int c0 = y[0], c1 = y[1], c2 = y[2];
		 if(c0 > 0 && c1 >= 0 && c2 == 0) return 0;
		 if(c1 > 0 && c2 >= 0 && c0 == 0) return 1;
		 if(c2 > 0 && c0 >= 0 && c1 == 0) return 2;
	}
}
 
int Move(vector<int> y) {
	if(a == 2) return sol1::Move(y);
	else return sol2::Move(y);
}

Compilation message

Catherine.cpp: In function 'int sol2::Move(std::vector<int>)':
Catherine.cpp:73:2: warning: control reaches end of non-void function [-Wreturn-type]
   73 |  }
      |  ^
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 16364 KB Output is correct
2 Correct 1 ms 1508 KB Output is correct
3 Correct 40 ms 15684 KB Output is correct
4 Correct 63 ms 17616 KB Output is correct
5 Correct 63 ms 17976 KB Output is correct
6 Correct 53 ms 16216 KB Output is correct
7 Correct 48 ms 16212 KB Output is correct
8 Correct 54 ms 17052 KB Output is correct
9 Correct 54 ms 16916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 16364 KB Output is correct
2 Correct 1 ms 1508 KB Output is correct
3 Correct 40 ms 15684 KB Output is correct
4 Correct 63 ms 17616 KB Output is correct
5 Correct 63 ms 17976 KB Output is correct
6 Correct 53 ms 16216 KB Output is correct
7 Correct 48 ms 16212 KB Output is correct
8 Correct 54 ms 17052 KB Output is correct
9 Correct 54 ms 16916 KB Output is correct
10 Correct 46 ms 14196 KB Output is correct
11 Correct 47 ms 14304 KB Output is correct
12 Correct 44 ms 14216 KB Output is correct
13 Correct 45 ms 14332 KB Output is correct
14 Correct 46 ms 14552 KB Output is correct
15 Correct 51 ms 14784 KB Output is correct
16 Correct 56 ms 17088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 14100 KB Output is correct
2 Correct 2 ms 1516 KB Output is correct
3 Correct 49 ms 13476 KB Output is correct
4 Correct 63 ms 15232 KB Output is correct
5 Correct 60 ms 15320 KB Output is correct
6 Correct 47 ms 13988 KB Output is correct
7 Correct 56 ms 14040 KB Output is correct
8 Correct 56 ms 14728 KB Output is correct
9 Correct 56 ms 14668 KB Output is correct
10 Correct 49 ms 14484 KB Output is correct
11 Correct 52 ms 14440 KB Output is correct
12 Correct 49 ms 14392 KB Output is correct
13 Correct 53 ms 14448 KB Output is correct
14 Correct 68 ms 14560 KB Output is correct
15 Correct 60 ms 14732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 14100 KB Output is correct
2 Correct 2 ms 1516 KB Output is correct
3 Correct 49 ms 13476 KB Output is correct
4 Correct 63 ms 15232 KB Output is correct
5 Correct 60 ms 15320 KB Output is correct
6 Correct 47 ms 13988 KB Output is correct
7 Correct 56 ms 14040 KB Output is correct
8 Correct 56 ms 14728 KB Output is correct
9 Correct 56 ms 14668 KB Output is correct
10 Correct 49 ms 14484 KB Output is correct
11 Correct 52 ms 14440 KB Output is correct
12 Correct 49 ms 14392 KB Output is correct
13 Correct 53 ms 14448 KB Output is correct
14 Correct 68 ms 14560 KB Output is correct
15 Correct 60 ms 14732 KB Output is correct
16 Correct 39 ms 12396 KB Output is correct
17 Correct 49 ms 12536 KB Output is correct
18 Correct 44 ms 12372 KB Output is correct
19 Correct 40 ms 12428 KB Output is correct
20 Correct 48 ms 13032 KB Output is correct
21 Correct 54 ms 12748 KB Output is correct
22 Correct 69 ms 14748 KB Output is correct
23 Correct 44 ms 12480 KB Output is correct
24 Correct 40 ms 12616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1788 KB Output is correct
2 Correct 2 ms 1516 KB Output is correct
3 Correct 3 ms 1704 KB Output is correct
4 Correct 2 ms 1780 KB Output is correct
5 Correct 3 ms 1776 KB Output is correct
6 Correct 3 ms 1772 KB Output is correct
7 Correct 3 ms 1776 KB Output is correct
8 Correct 2 ms 1776 KB Output is correct
9 Correct 3 ms 1776 KB Output is correct
10 Correct 2 ms 1792 KB Output is correct
11 Correct 3 ms 1780 KB Output is correct
12 Correct 3 ms 1776 KB Output is correct
13 Correct 3 ms 1788 KB Output is correct
14 Correct 2 ms 1776 KB Output is correct
15 Correct 3 ms 1776 KB Output is correct
16 Correct 2 ms 1776 KB Output is correct
17 Correct 2 ms 1784 KB Output is correct
18 Correct 3 ms 1776 KB Output is correct
19 Correct 3 ms 1784 KB Output is correct
20 Correct 2 ms 1776 KB Output is correct
21 Correct 3 ms 1792 KB Output is correct
22 Correct 3 ms 1776 KB Output is correct
23 Correct 3 ms 1776 KB Output is correct
24 Correct 2 ms 1776 KB Output is correct
25 Correct 2 ms 1776 KB Output is correct
26 Correct 3 ms 1784 KB Output is correct
27 Correct 2 ms 1780 KB Output is correct
28 Correct 3 ms 1776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 12228 KB Output is correct
2 Correct 52 ms 13280 KB Output is correct
3 Correct 2 ms 1516 KB Output is correct
4 Correct 34 ms 11948 KB Output is correct
5 Correct 52 ms 14796 KB Output is correct
6 Correct 60 ms 14824 KB Output is correct
7 Correct 53 ms 13984 KB Output is correct
8 Correct 44 ms 13952 KB Output is correct
9 Correct 61 ms 14812 KB Output is correct
10 Correct 59 ms 14824 KB Output is correct
11 Correct 52 ms 14784 KB Output is correct
12 Correct 57 ms 14772 KB Output is correct
13 Correct 54 ms 14840 KB Output is correct
14 Correct 52 ms 14860 KB Output is correct
15 Correct 70 ms 14872 KB Output is correct
16 Correct 52 ms 14816 KB Output is correct
17 Correct 54 ms 14576 KB Output is correct
18 Correct 51 ms 14584 KB Output is correct
19 Correct 50 ms 14632 KB Output is correct
20 Correct 48 ms 14592 KB Output is correct
21 Correct 49 ms 14608 KB Output is correct
22 Correct 55 ms 14640 KB Output is correct
23 Correct 40 ms 12200 KB Output is correct
24 Correct 49 ms 12096 KB Output is correct
25 Correct 41 ms 12640 KB Output is correct
26 Correct 43 ms 12520 KB Output is correct
27 Correct 51 ms 13408 KB Output is correct
28 Correct 64 ms 13532 KB Output is correct
29 Correct 51 ms 13436 KB Output is correct
30 Correct 54 ms 13512 KB Output is correct
31 Correct 40 ms 12148 KB Output is correct
32 Correct 44 ms 12132 KB Output is correct
33 Correct 45 ms 12592 KB Output is correct
34 Correct 43 ms 12540 KB Output is correct
35 Correct 46 ms 13304 KB Output is correct
36 Correct 50 ms 13336 KB Output is correct
37 Correct 61 ms 13240 KB Output is correct
38 Correct 57 ms 13644 KB Output is correct
39 Correct 54 ms 13288 KB Output is correct
40 Correct 50 ms 13240 KB Output is correct
41 Correct 50 ms 13936 KB Output is correct
42 Correct 71 ms 13964 KB Output is correct
43 Correct 58 ms 13944 KB Output is correct
44 Correct 48 ms 14040 KB Output is correct
45 Correct 64 ms 14048 KB Output is correct
46 Correct 57 ms 14056 KB Output is correct
47 Correct 49 ms 13136 KB Output is correct
48 Correct 53 ms 13080 KB Output is correct
49 Correct 46 ms 12956 KB Output is correct
50 Correct 59 ms 13160 KB Output is correct
51 Correct 40 ms 12360 KB Output is correct
52 Correct 45 ms 12324 KB Output is correct
53 Correct 48 ms 12308 KB Output is correct
54 Correct 43 ms 12256 KB Output is correct
55 Correct 51 ms 12296 KB Output is correct
56 Correct 48 ms 12356 KB Output is correct
57 Correct 48 ms 12164 KB Output is correct
58 Correct 49 ms 12092 KB Output is correct
59 Correct 53 ms 12316 KB Output is correct
60 Correct 49 ms 12372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 12196 KB Output is correct
2 Correct 53 ms 13300 KB Output is correct
3 Correct 2 ms 1516 KB Output is correct
4 Correct 39 ms 11988 KB Output is correct
5 Correct 55 ms 14808 KB Output is correct
6 Correct 56 ms 14824 KB Output is correct
7 Correct 46 ms 13948 KB Output is correct
8 Correct 68 ms 13904 KB Output is correct
9 Correct 62 ms 14808 KB Output is correct
10 Correct 62 ms 14804 KB Output is correct
11 Correct 71 ms 14840 KB Output is correct
12 Correct 57 ms 14796 KB Output is correct
13 Correct 76 ms 14880 KB Output is correct
14 Correct 68 ms 14784 KB Output is correct
15 Correct 69 ms 14988 KB Output is correct
16 Correct 55 ms 14808 KB Output is correct
17 Correct 68 ms 14556 KB Output is correct
18 Correct 52 ms 14540 KB Output is correct
19 Correct 49 ms 14564 KB Output is correct
20 Correct 49 ms 14560 KB Output is correct
21 Correct 51 ms 14576 KB Output is correct
22 Correct 61 ms 14452 KB Output is correct
23 Correct 41 ms 12136 KB Output is correct
24 Correct 46 ms 12124 KB Output is correct
25 Correct 48 ms 12596 KB Output is correct
26 Correct 51 ms 12484 KB Output is correct
27 Correct 66 ms 13316 KB Output is correct
28 Correct 61 ms 13492 KB Output is correct
29 Correct 58 ms 13572 KB Output is correct
30 Correct 54 ms 13524 KB Output is correct
31 Correct 44 ms 12196 KB Output is correct
32 Correct 43 ms 12132 KB Output is correct
33 Correct 54 ms 12500 KB Output is correct
34 Correct 46 ms 12608 KB Output is correct
35 Correct 59 ms 13280 KB Output is correct
36 Correct 57 ms 13296 KB Output is correct
37 Correct 66 ms 13228 KB Output is correct
38 Correct 59 ms 13416 KB Output is correct
39 Correct 56 ms 13288 KB Output is correct
40 Correct 59 ms 13268 KB Output is correct
41 Correct 52 ms 13936 KB Output is correct
42 Correct 56 ms 13996 KB Output is correct
43 Correct 76 ms 13904 KB Output is correct
44 Correct 51 ms 14064 KB Output is correct
45 Correct 50 ms 13916 KB Output is correct
46 Correct 59 ms 13944 KB Output is correct
47 Correct 52 ms 13140 KB Output is correct
48 Correct 47 ms 13040 KB Output is correct
49 Correct 49 ms 12952 KB Output is correct
50 Correct 60 ms 13116 KB Output is correct
51 Correct 51 ms 12252 KB Output is correct
52 Correct 45 ms 12252 KB Output is correct
53 Correct 46 ms 12356 KB Output is correct
54 Correct 45 ms 12288 KB Output is correct
55 Correct 46 ms 12348 KB Output is correct
56 Correct 45 ms 12316 KB Output is correct
57 Correct 47 ms 12416 KB Output is correct
58 Correct 40 ms 12128 KB Output is correct
59 Correct 44 ms 12464 KB Output is correct
60 Correct 49 ms 12380 KB Output is correct