#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(1);
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<=130){
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=1;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),56};
}
#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(1);
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<=130)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;
}
if(!found)exit(2);
vector<int> myseq;
for(int i=offset;i<l-1;i+=3){
if(myseq.size()==18)break;
myseq.emplace_back(res[i]);
}
if(!myseq.size()==18)exit(3);
for(int i=0;i<N;i++){
bool works = true;
for(int j=0;j<18;j++){
if(myseq[j]!=debrujin[i+j]){works=false;break;}
}
if(!works)continue;
return i*3+2-offset;
}
exit(4);
}
Compilation message
Bruno.cpp: In function 'int bruno(std::string)':
Bruno.cpp:60:18: warning: logical not is only applied to the left hand side of comparison [-Wlogical-not-parentheses]
60 | if(!myseq.size()==18)exit(3);
| ^~
Bruno.cpp:60:5: note: add parentheses around left hand side expression to silence this warning
60 | if(!myseq.size()==18)exit(3);
| ^~~~~~~~~~~~~
| ( )
Bruno.cpp:60:18: warning: comparison of constant '18' with boolean expression is always false [-Wbool-compare]
60 | if(!myseq.size()==18)exit(3);
| ~~~~~~~~~~~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
15996 KB |
Output is correct |
2 |
Correct |
37 ms |
15996 KB |
Output is correct |
3 |
Correct |
55 ms |
15996 KB |
Output is correct |
4 |
Correct |
50 ms |
16008 KB |
Output is correct |
5 |
Correct |
64 ms |
16252 KB |
Output is correct |
6 |
Correct |
43 ms |
15996 KB |
Output is correct |
7 |
Runtime error |
30 ms |
30624 KB |
Execution failed because the return code was nonzero |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
15996 KB |
Output is correct |
2 |
Correct |
37 ms |
15996 KB |
Output is correct |
3 |
Correct |
55 ms |
15996 KB |
Output is correct |
4 |
Correct |
50 ms |
16008 KB |
Output is correct |
5 |
Correct |
64 ms |
16252 KB |
Output is correct |
6 |
Correct |
43 ms |
15996 KB |
Output is correct |
7 |
Runtime error |
30 ms |
30624 KB |
Execution failed because the return code was nonzero |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
15996 KB |
Output is correct |
2 |
Correct |
37 ms |
15996 KB |
Output is correct |
3 |
Correct |
55 ms |
15996 KB |
Output is correct |
4 |
Correct |
50 ms |
16008 KB |
Output is correct |
5 |
Correct |
64 ms |
16252 KB |
Output is correct |
6 |
Correct |
43 ms |
15996 KB |
Output is correct |
7 |
Runtime error |
30 ms |
30624 KB |
Execution failed because the return code was nonzero |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
15996 KB |
Output is correct |
2 |
Correct |
37 ms |
15996 KB |
Output is correct |
3 |
Correct |
55 ms |
15996 KB |
Output is correct |
4 |
Correct |
50 ms |
16008 KB |
Output is correct |
5 |
Correct |
64 ms |
16252 KB |
Output is correct |
6 |
Correct |
43 ms |
15996 KB |
Output is correct |
7 |
Runtime error |
30 ms |
30624 KB |
Execution failed because the return code was nonzero |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
16112 KB |
Output is correct |
2 |
Correct |
54 ms |
16032 KB |
Output is correct |
3 |
Correct |
44 ms |
15980 KB |
Output is correct |
4 |
Correct |
38 ms |
16020 KB |
Output is correct |
5 |
Partially correct |
62 ms |
15992 KB |
Partially correct |
6 |
Partially correct |
61 ms |
16064 KB |
Partially correct |
7 |
Runtime error |
25 ms |
30740 KB |
Execution failed because the return code was nonzero |
8 |
Halted |
0 ms |
0 KB |
- |