Submission #829707

# Submission time Handle Problem Language Result Execution time Memory
829707 2023-08-18T14:16:20 Z MODDI Stray Cat (JOI20_stray) C++14
100 / 100
45 ms 16308 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;
	vector<int> q;
  	q.push_back(0);
	  for (int i = 0; i < (int)q.size(); i++) {
	    int v = q[i];
	    for (pii e : G[v]) if (dist[e.first] == N) {
	      dist[e.first] = dist[v] + 1;
	      q.push_back(e.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 = q[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++;
    }
    assert(c < 3);
    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;
  }
}
# Verdict Execution time Memory Grader output
1 Correct 28 ms 15340 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 23 ms 14632 KB Output is correct
4 Correct 44 ms 16276 KB Output is correct
5 Correct 35 ms 16308 KB Output is correct
6 Correct 26 ms 15120 KB Output is correct
7 Correct 26 ms 15064 KB Output is correct
8 Correct 37 ms 15832 KB Output is correct
9 Correct 40 ms 15940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 15340 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 23 ms 14632 KB Output is correct
4 Correct 44 ms 16276 KB Output is correct
5 Correct 35 ms 16308 KB Output is correct
6 Correct 26 ms 15120 KB Output is correct
7 Correct 26 ms 15064 KB Output is correct
8 Correct 37 ms 15832 KB Output is correct
9 Correct 40 ms 15940 KB Output is correct
10 Correct 25 ms 13072 KB Output is correct
11 Correct 25 ms 13172 KB Output is correct
12 Correct 26 ms 13164 KB Output is correct
13 Correct 25 ms 13200 KB Output is correct
14 Correct 26 ms 13328 KB Output is correct
15 Correct 30 ms 13780 KB Output is correct
16 Correct 32 ms 15924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 12820 KB Output is correct
2 Correct 0 ms 504 KB Output is correct
3 Correct 20 ms 12436 KB Output is correct
4 Correct 31 ms 14196 KB Output is correct
5 Correct 35 ms 14192 KB Output is correct
6 Correct 26 ms 12900 KB Output is correct
7 Correct 25 ms 12904 KB Output is correct
8 Correct 30 ms 13544 KB Output is correct
9 Correct 31 ms 13560 KB Output is correct
10 Correct 30 ms 13348 KB Output is correct
11 Correct 26 ms 13300 KB Output is correct
12 Correct 27 ms 13300 KB Output is correct
13 Correct 27 ms 13320 KB Output is correct
14 Correct 28 ms 13448 KB Output is correct
15 Correct 34 ms 13612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 12820 KB Output is correct
2 Correct 0 ms 504 KB Output is correct
3 Correct 20 ms 12436 KB Output is correct
4 Correct 31 ms 14196 KB Output is correct
5 Correct 35 ms 14192 KB Output is correct
6 Correct 26 ms 12900 KB Output is correct
7 Correct 25 ms 12904 KB Output is correct
8 Correct 30 ms 13544 KB Output is correct
9 Correct 31 ms 13560 KB Output is correct
10 Correct 30 ms 13348 KB Output is correct
11 Correct 26 ms 13300 KB Output is correct
12 Correct 27 ms 13300 KB Output is correct
13 Correct 27 ms 13320 KB Output is correct
14 Correct 28 ms 13448 KB Output is correct
15 Correct 34 ms 13612 KB Output is correct
16 Correct 23 ms 11248 KB Output is correct
17 Correct 24 ms 11260 KB Output is correct
18 Correct 26 ms 11272 KB Output is correct
19 Correct 24 ms 11216 KB Output is correct
20 Correct 26 ms 11876 KB Output is correct
21 Correct 27 ms 11620 KB Output is correct
22 Correct 33 ms 13520 KB Output is correct
23 Correct 38 ms 11284 KB Output is correct
24 Correct 28 ms 11508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 896 KB Output is correct
2 Correct 0 ms 508 KB Output is correct
3 Correct 0 ms 896 KB Output is correct
4 Correct 1 ms 904 KB Output is correct
5 Correct 1 ms 904 KB Output is correct
6 Correct 2 ms 904 KB Output is correct
7 Correct 2 ms 896 KB Output is correct
8 Correct 2 ms 896 KB Output is correct
9 Correct 2 ms 896 KB Output is correct
10 Correct 2 ms 896 KB Output is correct
11 Correct 2 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 896 KB Output is correct
15 Correct 1 ms 900 KB Output is correct
16 Correct 2 ms 900 KB Output is correct
17 Correct 2 ms 904 KB Output is correct
18 Correct 1 ms 892 KB Output is correct
19 Correct 2 ms 904 KB Output is correct
20 Correct 2 ms 896 KB Output is correct
21 Correct 1 ms 896 KB Output is correct
22 Correct 2 ms 900 KB Output is correct
23 Correct 0 ms 900 KB Output is correct
24 Correct 1 ms 904 KB Output is correct
25 Correct 0 ms 896 KB Output is correct
26 Correct 1 ms 896 KB Output is correct
27 Correct 2 ms 904 KB Output is correct
28 Correct 2 ms 896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 10996 KB Output is correct
2 Correct 35 ms 11516 KB Output is correct
3 Correct 0 ms 516 KB Output is correct
4 Correct 20 ms 10864 KB Output is correct
5 Correct 31 ms 12164 KB Output is correct
6 Correct 37 ms 12268 KB Output is correct
7 Correct 31 ms 11248 KB Output is correct
8 Correct 25 ms 11320 KB Output is correct
9 Correct 36 ms 12272 KB Output is correct
10 Correct 34 ms 12272 KB Output is correct
11 Correct 36 ms 12160 KB Output is correct
12 Correct 36 ms 12120 KB Output is correct
13 Correct 34 ms 12320 KB Output is correct
14 Correct 33 ms 12204 KB Output is correct
15 Correct 35 ms 12212 KB Output is correct
16 Correct 39 ms 12320 KB Output is correct
17 Correct 36 ms 11756 KB Output is correct
18 Correct 38 ms 11876 KB Output is correct
19 Correct 34 ms 11776 KB Output is correct
20 Correct 31 ms 11788 KB Output is correct
21 Correct 31 ms 11860 KB Output is correct
22 Correct 36 ms 11868 KB Output is correct
23 Correct 27 ms 11028 KB Output is correct
24 Correct 31 ms 11096 KB Output is correct
25 Correct 36 ms 11212 KB Output is correct
26 Correct 28 ms 11200 KB Output is correct
27 Correct 37 ms 11680 KB Output is correct
28 Correct 30 ms 11668 KB Output is correct
29 Correct 32 ms 11572 KB Output is correct
30 Correct 36 ms 11708 KB Output is correct
31 Correct 27 ms 11088 KB Output is correct
32 Correct 28 ms 11060 KB Output is correct
33 Correct 37 ms 11108 KB Output is correct
34 Correct 27 ms 11320 KB Output is correct
35 Correct 32 ms 11568 KB Output is correct
36 Correct 40 ms 11472 KB Output is correct
37 Correct 34 ms 11644 KB Output is correct
38 Correct 33 ms 11540 KB Output is correct
39 Correct 31 ms 11588 KB Output is correct
40 Correct 30 ms 11596 KB Output is correct
41 Correct 28 ms 11844 KB Output is correct
42 Correct 32 ms 11832 KB Output is correct
43 Correct 33 ms 11780 KB Output is correct
44 Correct 40 ms 11888 KB Output is correct
45 Correct 36 ms 11796 KB Output is correct
46 Correct 34 ms 11812 KB Output is correct
47 Correct 30 ms 11436 KB Output is correct
48 Correct 33 ms 11452 KB Output is correct
49 Correct 32 ms 11284 KB Output is correct
50 Correct 30 ms 11488 KB Output is correct
51 Correct 32 ms 11324 KB Output is correct
52 Correct 31 ms 11164 KB Output is correct
53 Correct 29 ms 11288 KB Output is correct
54 Correct 28 ms 11312 KB Output is correct
55 Correct 27 ms 11256 KB Output is correct
56 Correct 25 ms 11340 KB Output is correct
57 Correct 32 ms 11112 KB Output is correct
58 Correct 27 ms 11032 KB Output is correct
59 Correct 26 ms 11248 KB Output is correct
60 Correct 28 ms 11240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 11068 KB Output is correct
2 Correct 36 ms 11436 KB Output is correct
3 Correct 0 ms 508 KB Output is correct
4 Correct 25 ms 10844 KB Output is correct
5 Correct 33 ms 12244 KB Output is correct
6 Correct 37 ms 12280 KB Output is correct
7 Correct 28 ms 11164 KB Output is correct
8 Correct 33 ms 11224 KB Output is correct
9 Correct 37 ms 12088 KB Output is correct
10 Correct 40 ms 12164 KB Output is correct
11 Correct 41 ms 12232 KB Output is correct
12 Correct 38 ms 12220 KB Output is correct
13 Correct 38 ms 12124 KB Output is correct
14 Correct 45 ms 12248 KB Output is correct
15 Correct 33 ms 12208 KB Output is correct
16 Correct 33 ms 12232 KB Output is correct
17 Correct 30 ms 11908 KB Output is correct
18 Correct 37 ms 11796 KB Output is correct
19 Correct 35 ms 11784 KB Output is correct
20 Correct 27 ms 11988 KB Output is correct
21 Correct 34 ms 11784 KB Output is correct
22 Correct 40 ms 11860 KB Output is correct
23 Correct 25 ms 10920 KB Output is correct
24 Correct 30 ms 11120 KB Output is correct
25 Correct 25 ms 11212 KB Output is correct
26 Correct 30 ms 11228 KB Output is correct
27 Correct 30 ms 11640 KB Output is correct
28 Correct 32 ms 11704 KB Output is correct
29 Correct 32 ms 11728 KB Output is correct
30 Correct 36 ms 11680 KB Output is correct
31 Correct 28 ms 11032 KB Output is correct
32 Correct 24 ms 11120 KB Output is correct
33 Correct 32 ms 11216 KB Output is correct
34 Correct 31 ms 11216 KB Output is correct
35 Correct 32 ms 11624 KB Output is correct
36 Correct 30 ms 11704 KB Output is correct
37 Correct 27 ms 11572 KB Output is correct
38 Correct 33 ms 11656 KB Output is correct
39 Correct 27 ms 11576 KB Output is correct
40 Correct 27 ms 11632 KB Output is correct
41 Correct 27 ms 11836 KB Output is correct
42 Correct 31 ms 12016 KB Output is correct
43 Correct 28 ms 11824 KB Output is correct
44 Correct 28 ms 11952 KB Output is correct
45 Correct 36 ms 11892 KB Output is correct
46 Correct 30 ms 11976 KB Output is correct
47 Correct 27 ms 11404 KB Output is correct
48 Correct 27 ms 11568 KB Output is correct
49 Correct 27 ms 11372 KB Output is correct
50 Correct 27 ms 11552 KB Output is correct
51 Correct 25 ms 11300 KB Output is correct
52 Correct 27 ms 11376 KB Output is correct
53 Correct 25 ms 11384 KB Output is correct
54 Correct 26 ms 11376 KB Output is correct
55 Correct 27 ms 11268 KB Output is correct
56 Correct 25 ms 11392 KB Output is correct
57 Correct 25 ms 11200 KB Output is correct
58 Correct 25 ms 11144 KB Output is correct
59 Correct 25 ms 11216 KB Output is correct
60 Correct 24 ms 11156 KB Output is correct