Submission #1042751

# Submission time Handle Problem Language Result Execution time Memory
1042751 2024-08-03T10:33:47 Z Unforgettablepl Tricolor Lights (JOI24_tricolor) C++17
30 / 100
2000 ms 35740 KB
#include "Anna.h"
#include <bits/stdc++.h>
using namespace std;

namespace {

string calc(vector<int> arr,string S){
	int N = S.size();
	string res(N,'$');
	for(int i=0;i<N-1;i++){
		if(arr[i])continue;
		{
			vector<bool> present(3);
			if(S[i]=='R')present[0]=true;
			else if(S[i]=='G')present[1]=true;
			else if(S[i]=='B')present[2]=true;
			if(S[i+1]=='R')present[0]=true;
			else if(S[i+1]=='G')present[1]=true;
			else if(S[i+1]=='B')present[2]=true;
			if(!present[0])res[i]=res[i+1]='R';
			else if(!present[1])res[i]=res[i+1]='G';
			else if(!present[2])res[i]=res[i+1]='B';
		}
		for(int j=i-1;j>=0;j--){
			if(arr[j]!=1)break;
			vector<bool> present(3);
			if(S[j]=='R')present[0]=true;
			else if(S[j]=='G')present[1]=true;
			else if(S[j]=='B')present[2]=true;
			if(res[j+1]=='R')present[0]=true;
			else if(res[j+1]=='G')present[1]=true;
			else if(res[j+1]=='B')present[2]=true;
			if(!present[0])res[j]='R';
			else if(!present[1])res[j]='G';
			else if(!present[2])res[j]='B';
		}
		for(int j=i+2;j<N;j++){
			if(arr[j-1]!=1)break;
			vector<bool> present(3);
			if(S[j]=='R')present[0]=true;
			else if(S[j]=='G')present[1]=true;
			else if(S[j]=='B')present[2]=true;
			if(res[j-1]=='R')present[0]=true;
			else if(res[j-1]=='G')present[1]=true;
			else if(res[j-1]=='B')present[2]=true;
			if(!present[0])res[j]='R';
			else if(!present[1])res[j]='G';
			else if(!present[2])res[j]='B';	
		}
	}
	for(int i=0;i<N;i++){
		if(res[i]=='$'){
			if(S[i]=='R')res[i]='B';
			else if(S[i]=='B')res[i]='G';
			else if(S[i]=='G')res[i]='R';
		}
		for(int j=i+1;j<N;j++){
			if(arr[j-1]!=1)break;
			vector<bool> present(3);
			if(S[j]=='R')present[0]=true;
			else if(S[j]=='G')present[1]=true;
			else if(S[j]=='B')present[2]=true;
			if(res[j-1]=='R')present[0]=true;
			else if(res[j-1]=='G')present[1]=true;
			else if(res[j-1]=='B')present[2]=true;
			if(!present[0])res[j]='R';
			else if(!present[1])res[j]='G';
			else if(!present[2])res[j]='B';	
		}
	}
	return res;
}


vector<int> generateDe(int n){
	vector<int> debrujin;
	n--;
	for(int i=1;i<=n;i++)debrujin.emplace_back(0);
	vector<pair<bool,bool>> visited(1<<n);
	function<void(int)> dfs = [&](int x){
		if(!visited[x].first){
			debrujin.emplace_back(0);
			visited[x].first=true;
			dfs((x<<1)&((1<<n)-1));
		}
		if(!visited[x].second){
			debrujin.emplace_back(1);
			visited[x].second=true;
			dfs(((x<<1)&((1<<n)-1))+1);
		}
	};
	dfs(0);
	return debrujin;
}

}

pair<string, int> anna(int N, string S) {
	if(N<=61){
		string res;
		for(int i=0;i<N;i++){
			if(S[i]=='R')res.insert(res.end(),'B');
			else if(S[i]=='B')res.insert(res.end(),'G');
			else if(S[i]=='G')res.insert(res.end(),'R');
		}
		return {res,N};
	}
	auto debrujin = generateDe(18);
	vector<int> res(N+6,2);
	int itr = 0;
	for(int i=0;i<N;i+=3){
		if(debrujin[itr++]==0){
			res[i]=0;
			res[i+1]=1;
		} else {
			res[i-1]=res[i]=res[i+1]=1;
		}
	}
	return {calc(res,S),61};
}
#include "Bruno.h"
#include <bits/stdc++.h>
using namespace std;

namespace {

int N;
int l;

vector<int> generateDe(int n){
	vector<int> debrujin;
	n--;
	for(int i=1;i<=n;i++)debrujin.emplace_back(0);
	vector<pair<bool,bool>> visited(1<<n);
	function<void(int)> dfs = [&](int x){
		if(!visited[x].first){
			debrujin.emplace_back(0);
			visited[x].first=true;
			dfs((x<<1)&((1<<n)-1));
		}
		if(!visited[x].second){
			debrujin.emplace_back(1);
			visited[x].second=true;
			dfs(((x<<1)&((1<<n)-1))+1);
		}
	};
	dfs(0);
	return debrujin;
}

vector<int> debrujin;

}  // namespace

void init(int N, int l) {
	::N = N;
	::l = l;
	debrujin = generateDe(18);
}

int bruno(string u) {
	if(N<=61)return 1;
	vector<int> res(l-1);
	for(int i=0;i<l-1;i++)res[i]=u[i]!=u[i+1];
	bool found = false;
	int offset = 0;
	for(int i=0;i<l-2;i++){
		if(res[i])continue;
		if(res[i+1]==0)offset=(i+1)%3;
		else offset = i%3;
		found = true;
		break;
	}
	assert(found);
	vector<int> myseq;
	for(int i=offset;i<l-1;i+=3){
		myseq.emplace_back(res[i]);
	}
	for(int i=0;i<N;i++){
		bool works = true;
		for(int j=0;j<myseq.size();j++){
			if(myseq[j]!=debrujin[i+j]){works=false;break;}
		}
		if(!works)continue;
		assert(i*3+1-offset<=N);
		return i*3+1-offset;
	}
	assert(false);
}

Compilation message

Bruno.cpp: In function 'int bruno(std::string)':
Bruno.cpp:61:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |   for(int j=0;j<myseq.size();j++){
      |               ~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 33 ms 16004 KB Output is correct
2 Correct 34 ms 15964 KB Output is correct
3 Correct 41 ms 16008 KB Output is correct
4 Correct 36 ms 16004 KB Output is correct
5 Correct 37 ms 16052 KB Output is correct
6 Correct 76 ms 30828 KB Output is correct
7 Correct 52 ms 30816 KB Output is correct
8 Correct 56 ms 30724 KB Output is correct
9 Correct 54 ms 15996 KB Output is correct
10 Correct 55 ms 15996 KB Output is correct
11 Correct 36 ms 15996 KB Output is correct
12 Correct 40 ms 16000 KB Output is correct
13 Correct 58 ms 15916 KB Output is correct
14 Correct 56 ms 16016 KB Output is correct
15 Correct 36 ms 15996 KB Output is correct
16 Correct 37 ms 15920 KB Output is correct
17 Correct 59 ms 16036 KB Output is correct
18 Correct 37 ms 15948 KB Output is correct
19 Correct 37 ms 16004 KB Output is correct
20 Correct 37 ms 15972 KB Output is correct
21 Correct 37 ms 15964 KB Output is correct
22 Correct 39 ms 16068 KB Output is correct
23 Correct 37 ms 16028 KB Output is correct
24 Correct 38 ms 16000 KB Output is correct
25 Correct 39 ms 15920 KB Output is correct
26 Correct 36 ms 16008 KB Output is correct
27 Correct 38 ms 15912 KB Output is correct
28 Correct 52 ms 30656 KB Output is correct
29 Correct 53 ms 30660 KB Output is correct
30 Correct 56 ms 30544 KB Output is correct
31 Correct 62 ms 30696 KB Output is correct
32 Correct 73 ms 30620 KB Output is correct
33 Correct 55 ms 30956 KB Output is correct
34 Correct 34 ms 15916 KB Output is correct
35 Correct 55 ms 15988 KB Output is correct
36 Correct 39 ms 15932 KB Output is correct
37 Correct 61 ms 30628 KB Output is correct
38 Correct 57 ms 30684 KB Output is correct
39 Correct 65 ms 30740 KB Output is correct
40 Correct 62 ms 30712 KB Output is correct
41 Correct 62 ms 30756 KB Output is correct
42 Correct 63 ms 30872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 16004 KB Output is correct
2 Correct 34 ms 15964 KB Output is correct
3 Correct 41 ms 16008 KB Output is correct
4 Correct 36 ms 16004 KB Output is correct
5 Correct 37 ms 16052 KB Output is correct
6 Correct 76 ms 30828 KB Output is correct
7 Correct 52 ms 30816 KB Output is correct
8 Correct 56 ms 30724 KB Output is correct
9 Correct 54 ms 15996 KB Output is correct
10 Correct 55 ms 15996 KB Output is correct
11 Correct 36 ms 15996 KB Output is correct
12 Correct 40 ms 16000 KB Output is correct
13 Correct 58 ms 15916 KB Output is correct
14 Correct 56 ms 16016 KB Output is correct
15 Correct 36 ms 15996 KB Output is correct
16 Correct 37 ms 15920 KB Output is correct
17 Correct 59 ms 16036 KB Output is correct
18 Correct 37 ms 15948 KB Output is correct
19 Correct 37 ms 16004 KB Output is correct
20 Correct 37 ms 15972 KB Output is correct
21 Correct 37 ms 15964 KB Output is correct
22 Correct 39 ms 16068 KB Output is correct
23 Correct 37 ms 16028 KB Output is correct
24 Correct 38 ms 16000 KB Output is correct
25 Correct 39 ms 15920 KB Output is correct
26 Correct 36 ms 16008 KB Output is correct
27 Correct 38 ms 15912 KB Output is correct
28 Correct 52 ms 30656 KB Output is correct
29 Correct 53 ms 30660 KB Output is correct
30 Correct 56 ms 30544 KB Output is correct
31 Correct 62 ms 30696 KB Output is correct
32 Correct 73 ms 30620 KB Output is correct
33 Correct 55 ms 30956 KB Output is correct
34 Correct 34 ms 15916 KB Output is correct
35 Correct 55 ms 15988 KB Output is correct
36 Correct 39 ms 15932 KB Output is correct
37 Correct 61 ms 30628 KB Output is correct
38 Correct 57 ms 30684 KB Output is correct
39 Correct 65 ms 30740 KB Output is correct
40 Correct 62 ms 30712 KB Output is correct
41 Correct 62 ms 30756 KB Output is correct
42 Correct 63 ms 30872 KB Output is correct
43 Correct 59 ms 30844 KB Output is correct
44 Correct 64 ms 30724 KB Output is correct
45 Correct 64 ms 30684 KB Output is correct
46 Correct 54 ms 30536 KB Output is correct
47 Correct 54 ms 30696 KB Output is correct
48 Correct 66 ms 30680 KB Output is correct
49 Correct 74 ms 30712 KB Output is correct
50 Correct 85 ms 30612 KB Output is correct
51 Correct 68 ms 30696 KB Output is correct
52 Correct 61 ms 30620 KB Output is correct
53 Correct 81 ms 30624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 16004 KB Output is correct
2 Correct 34 ms 15964 KB Output is correct
3 Correct 41 ms 16008 KB Output is correct
4 Correct 36 ms 16004 KB Output is correct
5 Correct 37 ms 16052 KB Output is correct
6 Correct 76 ms 30828 KB Output is correct
7 Correct 52 ms 30816 KB Output is correct
8 Correct 56 ms 30724 KB Output is correct
9 Correct 54 ms 15996 KB Output is correct
10 Correct 55 ms 15996 KB Output is correct
11 Correct 36 ms 15996 KB Output is correct
12 Correct 40 ms 16000 KB Output is correct
13 Correct 58 ms 15916 KB Output is correct
14 Correct 56 ms 16016 KB Output is correct
15 Correct 36 ms 15996 KB Output is correct
16 Correct 37 ms 15920 KB Output is correct
17 Correct 59 ms 16036 KB Output is correct
18 Correct 37 ms 15948 KB Output is correct
19 Correct 37 ms 16004 KB Output is correct
20 Correct 37 ms 15972 KB Output is correct
21 Correct 37 ms 15964 KB Output is correct
22 Correct 39 ms 16068 KB Output is correct
23 Correct 37 ms 16028 KB Output is correct
24 Correct 38 ms 16000 KB Output is correct
25 Correct 39 ms 15920 KB Output is correct
26 Correct 36 ms 16008 KB Output is correct
27 Correct 38 ms 15912 KB Output is correct
28 Correct 52 ms 30656 KB Output is correct
29 Correct 53 ms 30660 KB Output is correct
30 Correct 56 ms 30544 KB Output is correct
31 Correct 62 ms 30696 KB Output is correct
32 Correct 73 ms 30620 KB Output is correct
33 Correct 55 ms 30956 KB Output is correct
34 Correct 34 ms 15916 KB Output is correct
35 Correct 55 ms 15988 KB Output is correct
36 Correct 39 ms 15932 KB Output is correct
37 Correct 61 ms 30628 KB Output is correct
38 Correct 57 ms 30684 KB Output is correct
39 Correct 65 ms 30740 KB Output is correct
40 Correct 62 ms 30712 KB Output is correct
41 Correct 62 ms 30756 KB Output is correct
42 Correct 63 ms 30872 KB Output is correct
43 Correct 59 ms 30844 KB Output is correct
44 Correct 64 ms 30724 KB Output is correct
45 Correct 64 ms 30684 KB Output is correct
46 Correct 54 ms 30536 KB Output is correct
47 Correct 54 ms 30696 KB Output is correct
48 Correct 66 ms 30680 KB Output is correct
49 Correct 74 ms 30712 KB Output is correct
50 Correct 85 ms 30612 KB Output is correct
51 Correct 68 ms 30696 KB Output is correct
52 Correct 61 ms 30620 KB Output is correct
53 Correct 81 ms 30624 KB Output is correct
54 Correct 61 ms 30624 KB Output is correct
55 Correct 83 ms 30716 KB Output is correct
56 Correct 57 ms 30652 KB Output is correct
57 Correct 84 ms 30712 KB Output is correct
58 Correct 72 ms 30724 KB Output is correct
59 Correct 72 ms 30620 KB Output is correct
60 Correct 83 ms 30624 KB Output is correct
61 Correct 62 ms 30724 KB Output is correct
62 Correct 56 ms 30680 KB Output is correct
63 Correct 81 ms 30740 KB Output is correct
64 Correct 83 ms 30800 KB Output is correct
65 Correct 85 ms 30620 KB Output is correct
66 Correct 54 ms 30860 KB Output is correct
67 Correct 87 ms 30740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 16004 KB Output is correct
2 Correct 34 ms 15964 KB Output is correct
3 Correct 41 ms 16008 KB Output is correct
4 Correct 36 ms 16004 KB Output is correct
5 Correct 37 ms 16052 KB Output is correct
6 Correct 76 ms 30828 KB Output is correct
7 Correct 52 ms 30816 KB Output is correct
8 Correct 56 ms 30724 KB Output is correct
9 Correct 54 ms 15996 KB Output is correct
10 Correct 55 ms 15996 KB Output is correct
11 Correct 36 ms 15996 KB Output is correct
12 Correct 40 ms 16000 KB Output is correct
13 Correct 58 ms 15916 KB Output is correct
14 Correct 56 ms 16016 KB Output is correct
15 Correct 36 ms 15996 KB Output is correct
16 Correct 37 ms 15920 KB Output is correct
17 Correct 59 ms 16036 KB Output is correct
18 Correct 37 ms 15948 KB Output is correct
19 Correct 37 ms 16004 KB Output is correct
20 Correct 37 ms 15972 KB Output is correct
21 Correct 37 ms 15964 KB Output is correct
22 Correct 39 ms 16068 KB Output is correct
23 Correct 37 ms 16028 KB Output is correct
24 Correct 38 ms 16000 KB Output is correct
25 Correct 39 ms 15920 KB Output is correct
26 Correct 36 ms 16008 KB Output is correct
27 Correct 38 ms 15912 KB Output is correct
28 Correct 52 ms 30656 KB Output is correct
29 Correct 53 ms 30660 KB Output is correct
30 Correct 56 ms 30544 KB Output is correct
31 Correct 62 ms 30696 KB Output is correct
32 Correct 73 ms 30620 KB Output is correct
33 Correct 55 ms 30956 KB Output is correct
34 Correct 34 ms 15916 KB Output is correct
35 Correct 55 ms 15988 KB Output is correct
36 Correct 39 ms 15932 KB Output is correct
37 Correct 61 ms 30628 KB Output is correct
38 Correct 57 ms 30684 KB Output is correct
39 Correct 65 ms 30740 KB Output is correct
40 Correct 62 ms 30712 KB Output is correct
41 Correct 62 ms 30756 KB Output is correct
42 Correct 63 ms 30872 KB Output is correct
43 Correct 59 ms 30844 KB Output is correct
44 Correct 64 ms 30724 KB Output is correct
45 Correct 64 ms 30684 KB Output is correct
46 Correct 54 ms 30536 KB Output is correct
47 Correct 54 ms 30696 KB Output is correct
48 Correct 66 ms 30680 KB Output is correct
49 Correct 74 ms 30712 KB Output is correct
50 Correct 85 ms 30612 KB Output is correct
51 Correct 68 ms 30696 KB Output is correct
52 Correct 61 ms 30620 KB Output is correct
53 Correct 81 ms 30624 KB Output is correct
54 Correct 61 ms 30624 KB Output is correct
55 Correct 83 ms 30716 KB Output is correct
56 Correct 57 ms 30652 KB Output is correct
57 Correct 84 ms 30712 KB Output is correct
58 Correct 72 ms 30724 KB Output is correct
59 Correct 72 ms 30620 KB Output is correct
60 Correct 83 ms 30624 KB Output is correct
61 Correct 62 ms 30724 KB Output is correct
62 Correct 56 ms 30680 KB Output is correct
63 Correct 81 ms 30740 KB Output is correct
64 Correct 83 ms 30800 KB Output is correct
65 Correct 85 ms 30620 KB Output is correct
66 Correct 54 ms 30860 KB Output is correct
67 Correct 87 ms 30740 KB Output is correct
68 Correct 148 ms 30644 KB Output is correct
69 Correct 111 ms 30624 KB Output is correct
70 Correct 117 ms 30624 KB Output is correct
71 Correct 107 ms 30556 KB Output is correct
72 Correct 130 ms 30624 KB Output is correct
73 Correct 127 ms 30704 KB Output is correct
74 Correct 138 ms 30752 KB Output is correct
75 Correct 123 ms 30624 KB Output is correct
76 Correct 127 ms 30584 KB Output is correct
77 Correct 136 ms 30708 KB Output is correct
78 Correct 104 ms 30732 KB Output is correct
79 Correct 99 ms 30624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 15996 KB Output is correct
2 Correct 45 ms 15912 KB Output is correct
3 Correct 38 ms 16004 KB Output is correct
4 Correct 53 ms 15980 KB Output is correct
5 Partially correct 44 ms 16000 KB Partially correct
6 Partially correct 57 ms 30712 KB Partially correct
7 Partially correct 63 ms 30600 KB Partially correct
8 Partially correct 74 ms 30644 KB Partially correct
9 Partially correct 72 ms 30696 KB Partially correct
10 Partially correct 62 ms 30612 KB Partially correct
11 Partially correct 57 ms 30656 KB Partially correct
12 Partially correct 63 ms 30644 KB Partially correct
13 Partially correct 130 ms 30608 KB Partially correct
14 Partially correct 141 ms 30532 KB Partially correct
15 Execution timed out 2021 ms 35740 KB Time limit exceeded
16 Halted 0 ms 0 KB -