답안 #1042824

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1042824 2024-08-03T12:47:59 Z Unforgettablepl Tricolor Lights (JOI24_tricolor) C++17
50 / 100
262 ms 46788 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--;
	vector<pair<bool,bool>> visited(1<<n);
	function<void(int)> dfs = [&](int x){
		if(!visited[x].first){
			visited[x].first=true;
			dfs((x<<1)&((1<<n)-1));
			debrujin.emplace_back(0);
		}
		if(!visited[x].second){
			visited[x].second=true;
			dfs(((x<<1)&((1<<n)-1))+1);
			debrujin.emplace_back(1);
		}
	};
	dfs(0);
	for(int i=1;i<=n;i++)debrujin.emplace_back(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--;
	vector<pair<bool,bool>> visited(1<<n);
	function<void(int)> dfs = [&](int x){
		if(!visited[x].first){
			visited[x].first=true;
			dfs((x<<1)&((1<<n)-1));
			debrujin.emplace_back(0);
		}
		if(!visited[x].second){
			visited[x].second=true;
			dfs(((x<<1)&((1<<n)-1))+1);
			debrujin.emplace_back(1);
		}
	};
	dfs(0);
	for(int i=1;i<=n;i++)debrujin.emplace_back(0);
	return debrujin;
}

vector<int> debrujin;
map<int,int> lookup;

}  // namespace

void init(int N, int l) {
	::N = N;
	::l = l;
	debrujin = generateDe(18);
	for(int i=0;i<N;i++){
		int curr = 0;
		for(int j=0;j<20;j++){
			if(debrujin[i+j])curr|=(1<<j);
		}
		lookup[curr]=i;
	}
}

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){
		if(myseq.size()==20)break;
		myseq.emplace_back(res[i]);
	}
	int curr = 0;
	for(int i=0;i<20;i++){
		if(myseq[i])curr|=(1<<i);
	}
	return lookup[curr]*3+1-offset;
	assert(false);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 16004 KB Output is correct
2 Correct 63 ms 16044 KB Output is correct
3 Correct 40 ms 15924 KB Output is correct
4 Correct 40 ms 15996 KB Output is correct
5 Correct 40 ms 15912 KB Output is correct
6 Correct 63 ms 30672 KB Output is correct
7 Correct 89 ms 30576 KB Output is correct
8 Correct 61 ms 30564 KB Output is correct
9 Correct 44 ms 15948 KB Output is correct
10 Correct 50 ms 16064 KB Output is correct
11 Correct 42 ms 15996 KB Output is correct
12 Correct 41 ms 15916 KB Output is correct
13 Correct 39 ms 16028 KB Output is correct
14 Correct 42 ms 15932 KB Output is correct
15 Correct 42 ms 15956 KB Output is correct
16 Correct 41 ms 15932 KB Output is correct
17 Correct 41 ms 15916 KB Output is correct
18 Correct 57 ms 15900 KB Output is correct
19 Correct 59 ms 15920 KB Output is correct
20 Correct 44 ms 15964 KB Output is correct
21 Correct 43 ms 15916 KB Output is correct
22 Correct 43 ms 16120 KB Output is correct
23 Correct 47 ms 15988 KB Output is correct
24 Correct 40 ms 15996 KB Output is correct
25 Correct 42 ms 15832 KB Output is correct
26 Correct 42 ms 15976 KB Output is correct
27 Correct 41 ms 15964 KB Output is correct
28 Correct 63 ms 30684 KB Output is correct
29 Correct 57 ms 30748 KB Output is correct
30 Correct 61 ms 30544 KB Output is correct
31 Correct 59 ms 30624 KB Output is correct
32 Correct 57 ms 30712 KB Output is correct
33 Correct 57 ms 30620 KB Output is correct
34 Correct 39 ms 16024 KB Output is correct
35 Correct 43 ms 15916 KB Output is correct
36 Correct 52 ms 16020 KB Output is correct
37 Correct 57 ms 30740 KB Output is correct
38 Correct 56 ms 30980 KB Output is correct
39 Correct 61 ms 30672 KB Output is correct
40 Correct 62 ms 30744 KB Output is correct
41 Correct 64 ms 30720 KB Output is correct
42 Correct 60 ms 30764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 16004 KB Output is correct
2 Correct 63 ms 16044 KB Output is correct
3 Correct 40 ms 15924 KB Output is correct
4 Correct 40 ms 15996 KB Output is correct
5 Correct 40 ms 15912 KB Output is correct
6 Correct 63 ms 30672 KB Output is correct
7 Correct 89 ms 30576 KB Output is correct
8 Correct 61 ms 30564 KB Output is correct
9 Correct 44 ms 15948 KB Output is correct
10 Correct 50 ms 16064 KB Output is correct
11 Correct 42 ms 15996 KB Output is correct
12 Correct 41 ms 15916 KB Output is correct
13 Correct 39 ms 16028 KB Output is correct
14 Correct 42 ms 15932 KB Output is correct
15 Correct 42 ms 15956 KB Output is correct
16 Correct 41 ms 15932 KB Output is correct
17 Correct 41 ms 15916 KB Output is correct
18 Correct 57 ms 15900 KB Output is correct
19 Correct 59 ms 15920 KB Output is correct
20 Correct 44 ms 15964 KB Output is correct
21 Correct 43 ms 15916 KB Output is correct
22 Correct 43 ms 16120 KB Output is correct
23 Correct 47 ms 15988 KB Output is correct
24 Correct 40 ms 15996 KB Output is correct
25 Correct 42 ms 15832 KB Output is correct
26 Correct 42 ms 15976 KB Output is correct
27 Correct 41 ms 15964 KB Output is correct
28 Correct 63 ms 30684 KB Output is correct
29 Correct 57 ms 30748 KB Output is correct
30 Correct 61 ms 30544 KB Output is correct
31 Correct 59 ms 30624 KB Output is correct
32 Correct 57 ms 30712 KB Output is correct
33 Correct 57 ms 30620 KB Output is correct
34 Correct 39 ms 16024 KB Output is correct
35 Correct 43 ms 15916 KB Output is correct
36 Correct 52 ms 16020 KB Output is correct
37 Correct 57 ms 30740 KB Output is correct
38 Correct 56 ms 30980 KB Output is correct
39 Correct 61 ms 30672 KB Output is correct
40 Correct 62 ms 30744 KB Output is correct
41 Correct 64 ms 30720 KB Output is correct
42 Correct 60 ms 30764 KB Output is correct
43 Correct 64 ms 30668 KB Output is correct
44 Correct 62 ms 30640 KB Output is correct
45 Correct 60 ms 30636 KB Output is correct
46 Correct 60 ms 30656 KB Output is correct
47 Correct 63 ms 30768 KB Output is correct
48 Correct 68 ms 30812 KB Output is correct
49 Correct 65 ms 30552 KB Output is correct
50 Correct 56 ms 30724 KB Output is correct
51 Correct 69 ms 30688 KB Output is correct
52 Correct 60 ms 30744 KB Output is correct
53 Correct 62 ms 30680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 16004 KB Output is correct
2 Correct 63 ms 16044 KB Output is correct
3 Correct 40 ms 15924 KB Output is correct
4 Correct 40 ms 15996 KB Output is correct
5 Correct 40 ms 15912 KB Output is correct
6 Correct 63 ms 30672 KB Output is correct
7 Correct 89 ms 30576 KB Output is correct
8 Correct 61 ms 30564 KB Output is correct
9 Correct 44 ms 15948 KB Output is correct
10 Correct 50 ms 16064 KB Output is correct
11 Correct 42 ms 15996 KB Output is correct
12 Correct 41 ms 15916 KB Output is correct
13 Correct 39 ms 16028 KB Output is correct
14 Correct 42 ms 15932 KB Output is correct
15 Correct 42 ms 15956 KB Output is correct
16 Correct 41 ms 15932 KB Output is correct
17 Correct 41 ms 15916 KB Output is correct
18 Correct 57 ms 15900 KB Output is correct
19 Correct 59 ms 15920 KB Output is correct
20 Correct 44 ms 15964 KB Output is correct
21 Correct 43 ms 15916 KB Output is correct
22 Correct 43 ms 16120 KB Output is correct
23 Correct 47 ms 15988 KB Output is correct
24 Correct 40 ms 15996 KB Output is correct
25 Correct 42 ms 15832 KB Output is correct
26 Correct 42 ms 15976 KB Output is correct
27 Correct 41 ms 15964 KB Output is correct
28 Correct 63 ms 30684 KB Output is correct
29 Correct 57 ms 30748 KB Output is correct
30 Correct 61 ms 30544 KB Output is correct
31 Correct 59 ms 30624 KB Output is correct
32 Correct 57 ms 30712 KB Output is correct
33 Correct 57 ms 30620 KB Output is correct
34 Correct 39 ms 16024 KB Output is correct
35 Correct 43 ms 15916 KB Output is correct
36 Correct 52 ms 16020 KB Output is correct
37 Correct 57 ms 30740 KB Output is correct
38 Correct 56 ms 30980 KB Output is correct
39 Correct 61 ms 30672 KB Output is correct
40 Correct 62 ms 30744 KB Output is correct
41 Correct 64 ms 30720 KB Output is correct
42 Correct 60 ms 30764 KB Output is correct
43 Correct 64 ms 30668 KB Output is correct
44 Correct 62 ms 30640 KB Output is correct
45 Correct 60 ms 30636 KB Output is correct
46 Correct 60 ms 30656 KB Output is correct
47 Correct 63 ms 30768 KB Output is correct
48 Correct 68 ms 30812 KB Output is correct
49 Correct 65 ms 30552 KB Output is correct
50 Correct 56 ms 30724 KB Output is correct
51 Correct 69 ms 30688 KB Output is correct
52 Correct 60 ms 30744 KB Output is correct
53 Correct 62 ms 30680 KB Output is correct
54 Correct 63 ms 30736 KB Output is correct
55 Correct 63 ms 30612 KB Output is correct
56 Correct 78 ms 30768 KB Output is correct
57 Correct 85 ms 30524 KB Output is correct
58 Correct 81 ms 30784 KB Output is correct
59 Correct 61 ms 30836 KB Output is correct
60 Correct 60 ms 30736 KB Output is correct
61 Correct 66 ms 30716 KB Output is correct
62 Correct 59 ms 30700 KB Output is correct
63 Correct 57 ms 30708 KB Output is correct
64 Correct 87 ms 30700 KB Output is correct
65 Correct 80 ms 30428 KB Output is correct
66 Correct 62 ms 30824 KB Output is correct
67 Correct 63 ms 30696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 16004 KB Output is correct
2 Correct 63 ms 16044 KB Output is correct
3 Correct 40 ms 15924 KB Output is correct
4 Correct 40 ms 15996 KB Output is correct
5 Correct 40 ms 15912 KB Output is correct
6 Correct 63 ms 30672 KB Output is correct
7 Correct 89 ms 30576 KB Output is correct
8 Correct 61 ms 30564 KB Output is correct
9 Correct 44 ms 15948 KB Output is correct
10 Correct 50 ms 16064 KB Output is correct
11 Correct 42 ms 15996 KB Output is correct
12 Correct 41 ms 15916 KB Output is correct
13 Correct 39 ms 16028 KB Output is correct
14 Correct 42 ms 15932 KB Output is correct
15 Correct 42 ms 15956 KB Output is correct
16 Correct 41 ms 15932 KB Output is correct
17 Correct 41 ms 15916 KB Output is correct
18 Correct 57 ms 15900 KB Output is correct
19 Correct 59 ms 15920 KB Output is correct
20 Correct 44 ms 15964 KB Output is correct
21 Correct 43 ms 15916 KB Output is correct
22 Correct 43 ms 16120 KB Output is correct
23 Correct 47 ms 15988 KB Output is correct
24 Correct 40 ms 15996 KB Output is correct
25 Correct 42 ms 15832 KB Output is correct
26 Correct 42 ms 15976 KB Output is correct
27 Correct 41 ms 15964 KB Output is correct
28 Correct 63 ms 30684 KB Output is correct
29 Correct 57 ms 30748 KB Output is correct
30 Correct 61 ms 30544 KB Output is correct
31 Correct 59 ms 30624 KB Output is correct
32 Correct 57 ms 30712 KB Output is correct
33 Correct 57 ms 30620 KB Output is correct
34 Correct 39 ms 16024 KB Output is correct
35 Correct 43 ms 15916 KB Output is correct
36 Correct 52 ms 16020 KB Output is correct
37 Correct 57 ms 30740 KB Output is correct
38 Correct 56 ms 30980 KB Output is correct
39 Correct 61 ms 30672 KB Output is correct
40 Correct 62 ms 30744 KB Output is correct
41 Correct 64 ms 30720 KB Output is correct
42 Correct 60 ms 30764 KB Output is correct
43 Correct 64 ms 30668 KB Output is correct
44 Correct 62 ms 30640 KB Output is correct
45 Correct 60 ms 30636 KB Output is correct
46 Correct 60 ms 30656 KB Output is correct
47 Correct 63 ms 30768 KB Output is correct
48 Correct 68 ms 30812 KB Output is correct
49 Correct 65 ms 30552 KB Output is correct
50 Correct 56 ms 30724 KB Output is correct
51 Correct 69 ms 30688 KB Output is correct
52 Correct 60 ms 30744 KB Output is correct
53 Correct 62 ms 30680 KB Output is correct
54 Correct 63 ms 30736 KB Output is correct
55 Correct 63 ms 30612 KB Output is correct
56 Correct 78 ms 30768 KB Output is correct
57 Correct 85 ms 30524 KB Output is correct
58 Correct 81 ms 30784 KB Output is correct
59 Correct 61 ms 30836 KB Output is correct
60 Correct 60 ms 30736 KB Output is correct
61 Correct 66 ms 30716 KB Output is correct
62 Correct 59 ms 30700 KB Output is correct
63 Correct 57 ms 30708 KB Output is correct
64 Correct 87 ms 30700 KB Output is correct
65 Correct 80 ms 30428 KB Output is correct
66 Correct 62 ms 30824 KB Output is correct
67 Correct 63 ms 30696 KB Output is correct
68 Correct 65 ms 30656 KB Output is correct
69 Correct 61 ms 30776 KB Output is correct
70 Correct 67 ms 30596 KB Output is correct
71 Correct 65 ms 30628 KB Output is correct
72 Correct 66 ms 30616 KB Output is correct
73 Correct 85 ms 30680 KB Output is correct
74 Correct 62 ms 30728 KB Output is correct
75 Correct 88 ms 30600 KB Output is correct
76 Correct 82 ms 30628 KB Output is correct
77 Correct 65 ms 30732 KB Output is correct
78 Correct 64 ms 30676 KB Output is correct
79 Correct 62 ms 30704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 16040 KB Output is correct
2 Correct 41 ms 15908 KB Output is correct
3 Correct 53 ms 15868 KB Output is correct
4 Correct 56 ms 15932 KB Output is correct
5 Partially correct 42 ms 15960 KB Partially correct
6 Partially correct 57 ms 30704 KB Partially correct
7 Partially correct 56 ms 30624 KB Partially correct
8 Partially correct 53 ms 30780 KB Partially correct
9 Partially correct 61 ms 30612 KB Partially correct
10 Partially correct 58 ms 30684 KB Partially correct
11 Partially correct 57 ms 30620 KB Partially correct
12 Partially correct 56 ms 30624 KB Partially correct
13 Partially correct 57 ms 30748 KB Partially correct
14 Partially correct 93 ms 30668 KB Partially correct
15 Partially correct 202 ms 46712 KB Partially correct
16 Partially correct 198 ms 46684 KB Partially correct
17 Partially correct 240 ms 46768 KB Partially correct
18 Correct 42 ms 15900 KB Output is correct
19 Correct 41 ms 16104 KB Output is correct
20 Correct 39 ms 15996 KB Output is correct
21 Correct 42 ms 15960 KB Output is correct
22 Correct 43 ms 15944 KB Output is correct
23 Partially correct 70 ms 15884 KB Partially correct
24 Partially correct 40 ms 15904 KB Partially correct
25 Partially correct 39 ms 15992 KB Partially correct
26 Partially correct 67 ms 15932 KB Partially correct
27 Partially correct 69 ms 15968 KB Partially correct
28 Partially correct 40 ms 16076 KB Partially correct
29 Partially correct 41 ms 15932 KB Partially correct
30 Partially correct 39 ms 15968 KB Partially correct
31 Partially correct 43 ms 15908 KB Partially correct
32 Partially correct 54 ms 15852 KB Partially correct
33 Partially correct 62 ms 15932 KB Partially correct
34 Partially correct 47 ms 15912 KB Partially correct
35 Partially correct 66 ms 15996 KB Partially correct
36 Partially correct 67 ms 15960 KB Partially correct
37 Partially correct 54 ms 30748 KB Partially correct
38 Partially correct 78 ms 30708 KB Partially correct
39 Partially correct 80 ms 30744 KB Partially correct
40 Partially correct 59 ms 30728 KB Partially correct
41 Partially correct 62 ms 30756 KB Partially correct
42 Partially correct 63 ms 30620 KB Partially correct
43 Partially correct 55 ms 30676 KB Partially correct
44 Partially correct 66 ms 30516 KB Partially correct
45 Partially correct 60 ms 30768 KB Partially correct
46 Partially correct 57 ms 30696 KB Partially correct
47 Partially correct 62 ms 30728 KB Partially correct
48 Partially correct 55 ms 30716 KB Partially correct
49 Partially correct 57 ms 30632 KB Partially correct
50 Partially correct 66 ms 30604 KB Partially correct
51 Partially correct 57 ms 30684 KB Partially correct
52 Partially correct 76 ms 30704 KB Partially correct
53 Partially correct 67 ms 30528 KB Partially correct
54 Partially correct 103 ms 34456 KB Partially correct
55 Partially correct 229 ms 46456 KB Partially correct
56 Partially correct 262 ms 46444 KB Partially correct
57 Partially correct 241 ms 46712 KB Partially correct
58 Correct 41 ms 15904 KB Output is correct
59 Correct 41 ms 15996 KB Output is correct
60 Partially correct 41 ms 15996 KB Partially correct
61 Partially correct 59 ms 30612 KB Partially correct
62 Partially correct 62 ms 30600 KB Partially correct
63 Partially correct 84 ms 30624 KB Partially correct
64 Partially correct 61 ms 30620 KB Partially correct
65 Partially correct 56 ms 30652 KB Partially correct
66 Partially correct 63 ms 30624 KB Partially correct
67 Partially correct 61 ms 30628 KB Partially correct
68 Partially correct 59 ms 30628 KB Partially correct
69 Partially correct 262 ms 46456 KB Partially correct
70 Partially correct 206 ms 46688 KB Partially correct
71 Partially correct 223 ms 46604 KB Partially correct
72 Partially correct 59 ms 30628 KB Partially correct
73 Partially correct 57 ms 30624 KB Partially correct
74 Partially correct 57 ms 30744 KB Partially correct
75 Partially correct 62 ms 30756 KB Partially correct
76 Partially correct 69 ms 30624 KB Partially correct
77 Partially correct 80 ms 30764 KB Partially correct
78 Partially correct 258 ms 46680 KB Partially correct
79 Partially correct 232 ms 46444 KB Partially correct
80 Partially correct 245 ms 46456 KB Partially correct
81 Partially correct 62 ms 30672 KB Partially correct
82 Partially correct 66 ms 30600 KB Partially correct
83 Partially correct 55 ms 30656 KB Partially correct
84 Partially correct 60 ms 30728 KB Partially correct
85 Partially correct 59 ms 30628 KB Partially correct
86 Partially correct 61 ms 30776 KB Partially correct
87 Partially correct 57 ms 30628 KB Partially correct
88 Partially correct 62 ms 30636 KB Partially correct
89 Partially correct 60 ms 30552 KB Partially correct
90 Partially correct 67 ms 30676 KB Partially correct
91 Partially correct 59 ms 30644 KB Partially correct
92 Partially correct 60 ms 30652 KB Partially correct
93 Partially correct 242 ms 46788 KB Partially correct
94 Partially correct 235 ms 46616 KB Partially correct
95 Partially correct 232 ms 46468 KB Partially correct