답안 #829671

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
829671 2023-08-18T14:01:45 Z MODDI 길고양이 (JOI20_stray) C++14
85 / 100
37 ms 15084 KB
#include "Anthony.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
namespace {
}  // namespace

std::vector<int> Mark(int N, int M, int A, int B, vector<int> U, vector<int> V) {
 	vi arr(M, -1);
 	vector<vector<pii>> G(N, vector<pii>());
 	for(int i = 0; i < M; i++){
 		int u = U[i], v = V[i];
 		G[u].pb({v, i});
 		G[v].pb({u, i});
	 }
	vi dist(N, N);
	dist[0] = 0;
	queue<int> q;
	q.push(0);
	vi ord;
	while(!q.empty()){
		int v = q.front();
		ord.pb(v);
		q.pop();
		for(pii next : G[v]){
			if(dist[next.first] == N){
				dist[next.first] = 1 + dist[v];
				q.push(next.first);
			}
		}
	}
	if(A >= 3){
		for(int i = 0; i < M; i++){
			arr[i] = min(dist[U[i]], dist[V[i]]) % 3;
		}
		return arr;
	}
	else{
		vi pib(N, -1);
		for(int i = 0; i < N; i++){
			int v = ord[i];
			if(i == 0){
				for(auto t : G[v]){
					arr[t.second] = 0;
				}
				continue;
			}
			int deg = (int) G[v].size();
			if(deg == 1)	continue;
			int par = -1, parC = -1;
			for(auto t : G[v]){
				if(dist[t.first] < dist[v]){
					par = t.first;
					parC = arr[t.second];
				}
			}
			if(deg == 2){
				if(pib[par] != -1){
					pib[v] = (pib[par] + 1) % 6;
				}
				else
					pib[v] = parC + 1;
				int col = (pib[v] == 0 || pib[v] == 2 || pib[v] == 3 ? 0 : 1);
				for(auto t : G[v]){
					if(t.first != par)
						arr[t.second] = col;
				}
			}
			else{
				for(auto t : G[v]){
					if(t.first != par)
						arr[t.second] = parC ^ 1;
				}
			}
			
		}
	}
	
	return arr;
}
#include "Catherine.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
namespace {
 
int A;
bool bP;
vector<int> colors;
 
bool Uping(vector<int> s) {
  vector<int> t = {1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0};
//  reverse(t.begin(), t.end());
  for (int i = 0; i + (int)s.size() <= (int)t.size(); i++) {
    bool ok = true;
    for (int j = 0; j < (int)s.size(); j++)
      ok &= s[j] == t[i + j];
    if (ok) return true;
  }
  return false;
}
 
}  // namespace
 
void Init(int A, int B) {
  A = A;
  bP = true;
  colors = vector<int>();
}
 
int Move(std::vector<int> y) {
	if (A > 2) {
		int c = 0;
	    while(c < 3) {
	      if (y[c] > 0 && y[(c + 2) % 3] == 0) break;
	      c++;
	    }
	    return c;
	  } 
	else{
		if(!colors.empty())	y[colors.back()]++;
		int deg = y[0] + y[1], col = -2;
		if(deg == 1){
			bP = false;
			if(colors.empty())	col = (y[0] > 0 ? 0 : 1);
			else col = -1;
		}
		else if (deg == 2) {
     		if (!bP) {
       			y[colors.back()]--;
        		col = (y[0] > 0 ? 0 : 1);
      		} 
		    else {
		        if ((int)colors.size() < 4) {
		          	if (!colors.empty()) y[colors.back()]--;
		         	col = (y[0] > 0 ? 0 : 1);
		         	if (colors.empty()) {
		            	y[col]--;
		            	colors.push_back((y[0] > 0 ? 0 : 1));
		         	}
	        	} 
				else {
			        y[colors.back()]--;
			        col = (y[0] > 0 ? 0 : 1);
			        vector<int> s = colors;
			    	s.push_back(col);
			        if (!Uping(s)) col = -1;
			        bP = false;
	        	}
	      	}
    	} 
		else {
		    bP = false;
		    col = (y[0] == 1 ? 0 : 1);
		    if (!colors.empty() && colors.back() == col) col = -1;
    	}
	    if (col == -1) {
	      int x = colors.back();
	      colors.push_back(x);
	    } else {
	      colors.push_back(col);
	    }
    return col;
  	}	
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 25 ms 15084 KB Wrong Answer [6]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 25 ms 15084 KB Wrong Answer [6]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 23 ms 12924 KB Wrong Answer [6]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 23 ms 12924 KB Wrong Answer [6]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 904 KB Output is correct
2 Correct 0 ms 508 KB Output is correct
3 Correct 1 ms 900 KB Output is correct
4 Correct 2 ms 896 KB Output is correct
5 Correct 1 ms 900 KB Output is correct
6 Correct 1 ms 896 KB Output is correct
7 Correct 2 ms 900 KB Output is correct
8 Correct 2 ms 900 KB Output is correct
9 Correct 2 ms 896 KB Output is correct
10 Correct 2 ms 904 KB Output is correct
11 Correct 1 ms 896 KB Output is correct
12 Correct 2 ms 896 KB Output is correct
13 Correct 2 ms 896 KB Output is correct
14 Correct 2 ms 840 KB Output is correct
15 Correct 2 ms 904 KB Output is correct
16 Correct 2 ms 896 KB Output is correct
17 Correct 2 ms 904 KB Output is correct
18 Correct 2 ms 896 KB Output is correct
19 Correct 2 ms 896 KB Output is correct
20 Correct 2 ms 896 KB Output is correct
21 Correct 2 ms 904 KB Output is correct
22 Correct 2 ms 896 KB Output is correct
23 Correct 2 ms 892 KB Output is correct
24 Correct 2 ms 904 KB Output is correct
25 Correct 2 ms 896 KB Output is correct
26 Correct 2 ms 904 KB Output is correct
27 Correct 2 ms 956 KB Output is correct
28 Correct 2 ms 896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 10988 KB Output is correct
2 Correct 26 ms 11628 KB Output is correct
3 Correct 0 ms 508 KB Output is correct
4 Correct 20 ms 10988 KB Output is correct
5 Correct 28 ms 12260 KB Output is correct
6 Correct 33 ms 12268 KB Output is correct
7 Correct 24 ms 11236 KB Output is correct
8 Correct 24 ms 11228 KB Output is correct
9 Correct 30 ms 12272 KB Output is correct
10 Correct 30 ms 12208 KB Output is correct
11 Correct 31 ms 12240 KB Output is correct
12 Correct 27 ms 12276 KB Output is correct
13 Correct 28 ms 12280 KB Output is correct
14 Correct 30 ms 12260 KB Output is correct
15 Correct 30 ms 12268 KB Output is correct
16 Correct 37 ms 12240 KB Output is correct
17 Correct 26 ms 11996 KB Output is correct
18 Correct 26 ms 11888 KB Output is correct
19 Correct 30 ms 11892 KB Output is correct
20 Correct 27 ms 11996 KB Output is correct
21 Correct 27 ms 11888 KB Output is correct
22 Correct 26 ms 11884 KB Output is correct
23 Correct 25 ms 11120 KB Output is correct
24 Correct 24 ms 11144 KB Output is correct
25 Correct 30 ms 11324 KB Output is correct
26 Correct 24 ms 11256 KB Output is correct
27 Correct 27 ms 11760 KB Output is correct
28 Correct 26 ms 11708 KB Output is correct
29 Correct 27 ms 11760 KB Output is correct
30 Correct 27 ms 11700 KB Output is correct
31 Correct 24 ms 11088 KB Output is correct
32 Correct 24 ms 11128 KB Output is correct
33 Correct 24 ms 11260 KB Output is correct
34 Correct 25 ms 11252 KB Output is correct
35 Correct 37 ms 11664 KB Output is correct
36 Correct 27 ms 11624 KB Output is correct
37 Correct 27 ms 11636 KB Output is correct
38 Correct 28 ms 11632 KB Output is correct
39 Correct 26 ms 11656 KB Output is correct
40 Correct 26 ms 11632 KB Output is correct
41 Correct 27 ms 11880 KB Output is correct
42 Correct 27 ms 11896 KB Output is correct
43 Correct 27 ms 11876 KB Output is correct
44 Correct 28 ms 11924 KB Output is correct
45 Correct 34 ms 12108 KB Output is correct
46 Correct 27 ms 11916 KB Output is correct
47 Correct 27 ms 11508 KB Output is correct
48 Correct 26 ms 11504 KB Output is correct
49 Correct 26 ms 11376 KB Output is correct
50 Correct 26 ms 11524 KB Output is correct
51 Correct 24 ms 11336 KB Output is correct
52 Correct 24 ms 11260 KB Output is correct
53 Correct 24 ms 11376 KB Output is correct
54 Correct 24 ms 11216 KB Output is correct
55 Correct 25 ms 11380 KB Output is correct
56 Correct 24 ms 11328 KB Output is correct
57 Correct 25 ms 11032 KB Output is correct
58 Correct 24 ms 11116 KB Output is correct
59 Correct 24 ms 11248 KB Output is correct
60 Correct 24 ms 11196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 11008 KB Output is correct
2 Correct 26 ms 11444 KB Output is correct
3 Correct 0 ms 508 KB Output is correct
4 Correct 20 ms 10984 KB Output is correct
5 Correct 28 ms 12260 KB Output is correct
6 Correct 30 ms 12240 KB Output is correct
7 Correct 25 ms 11264 KB Output is correct
8 Correct 24 ms 11264 KB Output is correct
9 Correct 30 ms 12108 KB Output is correct
10 Correct 34 ms 12232 KB Output is correct
11 Correct 30 ms 12208 KB Output is correct
12 Correct 36 ms 12188 KB Output is correct
13 Correct 27 ms 12268 KB Output is correct
14 Correct 27 ms 12284 KB Output is correct
15 Correct 27 ms 12264 KB Output is correct
16 Correct 28 ms 12152 KB Output is correct
17 Correct 27 ms 11828 KB Output is correct
18 Correct 26 ms 11880 KB Output is correct
19 Correct 26 ms 11892 KB Output is correct
20 Correct 27 ms 11976 KB Output is correct
21 Correct 27 ms 11984 KB Output is correct
22 Correct 26 ms 11936 KB Output is correct
23 Correct 23 ms 11120 KB Output is correct
24 Correct 25 ms 11108 KB Output is correct
25 Correct 25 ms 11244 KB Output is correct
26 Correct 24 ms 11304 KB Output is correct
27 Correct 27 ms 11736 KB Output is correct
28 Correct 28 ms 11740 KB Output is correct
29 Correct 26 ms 11772 KB Output is correct
30 Correct 32 ms 11728 KB Output is correct
31 Correct 24 ms 11076 KB Output is correct
32 Correct 24 ms 11120 KB Output is correct
33 Correct 24 ms 11244 KB Output is correct
34 Correct 24 ms 11320 KB Output is correct
35 Correct 27 ms 11592 KB Output is correct
36 Correct 26 ms 11620 KB Output is correct
37 Correct 26 ms 11664 KB Output is correct
38 Correct 27 ms 11620 KB Output is correct
39 Correct 27 ms 11632 KB Output is correct
40 Correct 32 ms 11696 KB Output is correct
41 Correct 26 ms 11884 KB Output is correct
42 Correct 26 ms 11900 KB Output is correct
43 Correct 27 ms 11892 KB Output is correct
44 Correct 27 ms 11992 KB Output is correct
45 Correct 26 ms 12016 KB Output is correct
46 Correct 26 ms 12000 KB Output is correct
47 Correct 26 ms 11492 KB Output is correct
48 Correct 26 ms 11528 KB Output is correct
49 Correct 25 ms 11392 KB Output is correct
50 Correct 27 ms 11592 KB Output is correct
51 Correct 24 ms 11376 KB Output is correct
52 Correct 25 ms 11372 KB Output is correct
53 Correct 24 ms 11380 KB Output is correct
54 Correct 24 ms 11376 KB Output is correct
55 Correct 24 ms 11352 KB Output is correct
56 Correct 26 ms 11384 KB Output is correct
57 Correct 25 ms 11068 KB Output is correct
58 Correct 24 ms 11104 KB Output is correct
59 Correct 24 ms 11244 KB Output is correct
60 Correct 24 ms 11168 KB Output is correct