답안 #829667

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
829667 2023-08-18T13:59:48 Z MODDI 길고양이 (JOI20_stray) C++14
85 / 100
38 ms 15100 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^1);
	    } else {
	      colors.push_back(col);
	    }
    return col;
  	}	
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 26 ms 15100 KB Wrong Answer [6]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 26 ms 15100 KB Wrong Answer [6]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 24 ms 12908 KB Wrong Answer [6]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 24 ms 12908 KB Wrong Answer [6]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 896 KB Output is correct
2 Correct 0 ms 512 KB Output is correct
3 Correct 2 ms 908 KB Output is correct
4 Correct 2 ms 900 KB Output is correct
5 Correct 2 ms 860 KB Output is correct
6 Correct 2 ms 908 KB Output is correct
7 Correct 2 ms 896 KB Output is correct
8 Correct 2 ms 900 KB Output is correct
9 Correct 2 ms 908 KB Output is correct
10 Correct 2 ms 908 KB Output is correct
11 Correct 1 ms 900 KB Output is correct
12 Correct 2 ms 908 KB Output is correct
13 Correct 2 ms 904 KB Output is correct
14 Correct 2 ms 900 KB Output is correct
15 Correct 1 ms 860 KB Output is correct
16 Correct 2 ms 892 KB Output is correct
17 Correct 1 ms 900 KB Output is correct
18 Correct 2 ms 900 KB Output is correct
19 Correct 2 ms 912 KB Output is correct
20 Correct 2 ms 860 KB Output is correct
21 Correct 1 ms 908 KB Output is correct
22 Correct 2 ms 900 KB Output is correct
23 Correct 2 ms 900 KB Output is correct
24 Correct 2 ms 912 KB Output is correct
25 Correct 2 ms 904 KB Output is correct
26 Correct 1 ms 900 KB Output is correct
27 Correct 2 ms 900 KB Output is correct
28 Correct 2 ms 908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 11056 KB Output is correct
2 Correct 27 ms 12084 KB Output is correct
3 Correct 0 ms 520 KB Output is correct
4 Correct 26 ms 11172 KB Output is correct
5 Correct 30 ms 12624 KB Output is correct
6 Correct 31 ms 12748 KB Output is correct
7 Correct 26 ms 11680 KB Output is correct
8 Correct 27 ms 11724 KB Output is correct
9 Correct 31 ms 12604 KB Output is correct
10 Correct 30 ms 12704 KB Output is correct
11 Correct 30 ms 12648 KB Output is correct
12 Correct 30 ms 12728 KB Output is correct
13 Correct 30 ms 12708 KB Output is correct
14 Correct 28 ms 12700 KB Output is correct
15 Correct 30 ms 12736 KB Output is correct
16 Correct 27 ms 12668 KB Output is correct
17 Correct 28 ms 12356 KB Output is correct
18 Correct 27 ms 12324 KB Output is correct
19 Correct 28 ms 12332 KB Output is correct
20 Correct 28 ms 12380 KB Output is correct
21 Correct 28 ms 12432 KB Output is correct
22 Correct 28 ms 12272 KB Output is correct
23 Correct 25 ms 11600 KB Output is correct
24 Correct 25 ms 11588 KB Output is correct
25 Correct 25 ms 11728 KB Output is correct
26 Correct 24 ms 11732 KB Output is correct
27 Correct 27 ms 12176 KB Output is correct
28 Correct 27 ms 12240 KB Output is correct
29 Correct 26 ms 12228 KB Output is correct
30 Correct 27 ms 12236 KB Output is correct
31 Correct 26 ms 11572 KB Output is correct
32 Correct 24 ms 11636 KB Output is correct
33 Correct 25 ms 11716 KB Output is correct
34 Correct 24 ms 11700 KB Output is correct
35 Correct 27 ms 12052 KB Output is correct
36 Correct 27 ms 12244 KB Output is correct
37 Correct 27 ms 12108 KB Output is correct
38 Correct 27 ms 12024 KB Output is correct
39 Correct 28 ms 12084 KB Output is correct
40 Correct 27 ms 12088 KB Output is correct
41 Correct 28 ms 12168 KB Output is correct
42 Correct 28 ms 12432 KB Output is correct
43 Correct 27 ms 12228 KB Output is correct
44 Correct 28 ms 12356 KB Output is correct
45 Correct 28 ms 12364 KB Output is correct
46 Correct 28 ms 12356 KB Output is correct
47 Correct 27 ms 11960 KB Output is correct
48 Correct 30 ms 12148 KB Output is correct
49 Correct 27 ms 11856 KB Output is correct
50 Correct 27 ms 12108 KB Output is correct
51 Correct 25 ms 11744 KB Output is correct
52 Correct 26 ms 11716 KB Output is correct
53 Correct 25 ms 11700 KB Output is correct
54 Correct 26 ms 11636 KB Output is correct
55 Correct 24 ms 11588 KB Output is correct
56 Correct 24 ms 11664 KB Output is correct
57 Correct 24 ms 11636 KB Output is correct
58 Correct 26 ms 11600 KB Output is correct
59 Correct 26 ms 11640 KB Output is correct
60 Correct 25 ms 11672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 11040 KB Output is correct
2 Correct 26 ms 11832 KB Output is correct
3 Correct 0 ms 512 KB Output is correct
4 Correct 20 ms 11304 KB Output is correct
5 Correct 31 ms 12676 KB Output is correct
6 Correct 31 ms 12700 KB Output is correct
7 Correct 27 ms 11656 KB Output is correct
8 Correct 26 ms 11732 KB Output is correct
9 Correct 30 ms 12668 KB Output is correct
10 Correct 31 ms 12632 KB Output is correct
11 Correct 28 ms 12748 KB Output is correct
12 Correct 30 ms 12712 KB Output is correct
13 Correct 28 ms 12708 KB Output is correct
14 Correct 30 ms 12720 KB Output is correct
15 Correct 30 ms 12704 KB Output is correct
16 Correct 30 ms 12660 KB Output is correct
17 Correct 28 ms 12376 KB Output is correct
18 Correct 28 ms 12404 KB Output is correct
19 Correct 26 ms 12360 KB Output is correct
20 Correct 27 ms 12388 KB Output is correct
21 Correct 27 ms 12336 KB Output is correct
22 Correct 27 ms 12352 KB Output is correct
23 Correct 25 ms 11400 KB Output is correct
24 Correct 24 ms 11556 KB Output is correct
25 Correct 24 ms 11684 KB Output is correct
26 Correct 25 ms 11724 KB Output is correct
27 Correct 28 ms 12216 KB Output is correct
28 Correct 32 ms 12184 KB Output is correct
29 Correct 27 ms 12204 KB Output is correct
30 Correct 27 ms 12184 KB Output is correct
31 Correct 25 ms 11600 KB Output is correct
32 Correct 25 ms 11608 KB Output is correct
33 Correct 26 ms 11788 KB Output is correct
34 Correct 26 ms 11716 KB Output is correct
35 Correct 27 ms 12016 KB Output is correct
36 Correct 27 ms 12048 KB Output is correct
37 Correct 27 ms 12100 KB Output is correct
38 Correct 27 ms 12096 KB Output is correct
39 Correct 27 ms 12132 KB Output is correct
40 Correct 27 ms 12004 KB Output is correct
41 Correct 28 ms 12336 KB Output is correct
42 Correct 38 ms 12268 KB Output is correct
43 Correct 27 ms 12228 KB Output is correct
44 Correct 28 ms 12224 KB Output is correct
45 Correct 28 ms 12372 KB Output is correct
46 Correct 28 ms 12460 KB Output is correct
47 Correct 27 ms 11932 KB Output is correct
48 Correct 27 ms 11984 KB Output is correct
49 Correct 27 ms 11752 KB Output is correct
50 Correct 27 ms 12108 KB Output is correct
51 Correct 28 ms 11720 KB Output is correct
52 Correct 24 ms 11680 KB Output is correct
53 Correct 25 ms 11696 KB Output is correct
54 Correct 25 ms 11724 KB Output is correct
55 Correct 25 ms 11748 KB Output is correct
56 Correct 25 ms 11680 KB Output is correct
57 Correct 25 ms 11580 KB Output is correct
58 Correct 24 ms 11596 KB Output is correct
59 Correct 24 ms 11632 KB Output is correct
60 Correct 25 ms 11716 KB Output is correct