#include "ancient2.h"
#include <string>
#include <vector>
namespace {
int variable_example = 1;
} // namespace
#include<bits/stdc++.h>
using namespace std;
int n;
string ans;
int si[1000],sj[1000],sk[1000];
bool check(int i,int j,char c){
ans[i]=c;
for(int k=i-j; k>=j-1 ;k-=j){
bool same=true;
for(int l=0; l<j ;l++){
if(ans[k-l]!=ans[i-l]){
same=false;break;
}
}
if(same) return false;
}
return true;
}
int build(int i,int j,int cl){
int m=2*j+1+cl;
vector<int>a(m),b(m);
for(int k=0; k<j ;k++){
a[k]=a[k+j]=b[k]=b[k+j]=k%j+1;
if(ans[i-j+1+k]=='0') a[k+j]+=j;
else b[k+j]+=j;
}
int iu=2*j+1;
a[2*j]=iu;
b[2*j]=iu+(1000-i)%cl;
for(int k=0; k<cl ;k++){
a[iu+k]=b[iu+k]=iu+(k+1)%cl;
}
int st=j-i%j-1;
if(st==0) st=j;
for(auto &c:a) if(c==0 || c==st) c^=st;
for(auto &c:b) if(c==0 || c==st) c^=st;
swap(a[0],a[st]);
swap(b[0],b[st]);
int res=Query(m,a,b);
return res;
}
void boom(int i,int j){
//cout << "BOOM " << i << ' ' << j << ' ' << ans[i] << endl;
int cl=1;
while(cl*(cl+1)<(1000-i)*2) cl++;
int res=build(i,j,cl);
if(res<2*j){//string not found
ans[i]^=1;
return;
}
if(i==n-1) return;
if(res==2*j){
ans[n-1]=ans[i];
ans[i]^=1;
return;
}
int res2=build(i,j,cl+1);
int r1=res-2*j-1,r2=res2-2*j-1;
int z=0;
//if(res2==52) exit(0);
while(z%cl!=r1 || z%(cl+1)!=r2) z++;
int pos=n-z%(1000-i)-2;
sj[i]=j;sk[i]=pos;
ans[pos]=ans[i];
ans[pos+1]='0'+(z>=(1000-i));
if(pos!=i) ans[i]^=1;
}
string Solve(int N){
n=N;
ans.resize(N);
for(int i=0; i<N ;i++) ans[i]='2';
for(int i=0; i<N ;i++){
//cout << "solve " << i << endl;
if(ans[i]!='2') continue;
{
for(int x=0; x<i ;x++){
if(sj[x]==0 || (i-x)%sj[x]!=0 || i>=sk[x]) continue;
bool same=true;
for(int j=1; j<sj[x] ;j++){
if(ans[i-j]!=ans[x-j]){
same=false;
break;
}
}
if(same){
ans[i]=ans[x];
break;
}
}
}
if(ans[i]!='2') continue;
for(int j=1; ;j++){
bool done=false;
if(check(i,j,'0')){
done=true;
boom(i,j);
}
else if(check(i,j,'1')){
done=true;
boom(i,j);
}
if(done) break;
}
//cout << "progress " << i << endl;
/*for(int i=0; i<n ;i++) cout << ans[i];
cout << endl;*/
}
return ans;
}
Compilation message
ancient2.cpp:8:5: warning: '{anonymous}::variable_example' defined but not used [-Wunused-variable]
8 | int variable_example = 1;
| ^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
208 KB |
Output is correct |
2 |
Correct |
10 ms |
308 KB |
Output is correct |
3 |
Correct |
6 ms |
208 KB |
Output is correct |
4 |
Correct |
7 ms |
312 KB |
Output is correct |
5 |
Correct |
9 ms |
316 KB |
Output is correct |
6 |
Correct |
5 ms |
208 KB |
Output is correct |
7 |
Correct |
6 ms |
312 KB |
Output is correct |
8 |
Correct |
7 ms |
308 KB |
Output is correct |
9 |
Correct |
4 ms |
208 KB |
Output is correct |
10 |
Correct |
4 ms |
300 KB |
Output is correct |
11 |
Correct |
6 ms |
308 KB |
Output is correct |
12 |
Correct |
7 ms |
300 KB |
Output is correct |
13 |
Correct |
12 ms |
208 KB |
Output is correct |
14 |
Correct |
11 ms |
320 KB |
Output is correct |
15 |
Correct |
7 ms |
316 KB |
Output is correct |
16 |
Correct |
12 ms |
208 KB |
Output is correct |
17 |
Correct |
16 ms |
292 KB |
Output is correct |
18 |
Correct |
7 ms |
316 KB |
Output is correct |
19 |
Correct |
9 ms |
312 KB |
Output is correct |
20 |
Correct |
6 ms |
208 KB |
Output is correct |
21 |
Correct |
13 ms |
316 KB |
Output is correct |
22 |
Correct |
13 ms |
316 KB |
Output is correct |
23 |
Correct |
14 ms |
292 KB |
Output is correct |
24 |
Correct |
13 ms |
208 KB |
Output is correct |
25 |
Correct |
14 ms |
316 KB |
Output is correct |
26 |
Correct |
14 ms |
312 KB |
Output is correct |
27 |
Correct |
10 ms |
316 KB |
Output is correct |
28 |
Correct |
15 ms |
208 KB |
Output is correct |
29 |
Correct |
12 ms |
208 KB |
Output is correct |
30 |
Correct |
13 ms |
312 KB |
Output is correct |
31 |
Correct |
12 ms |
208 KB |
Output is correct |
32 |
Correct |
11 ms |
312 KB |
Output is correct |
33 |
Correct |
13 ms |
312 KB |
Output is correct |
34 |
Correct |
8 ms |
208 KB |
Output is correct |
35 |
Correct |
9 ms |
316 KB |
Output is correct |
36 |
Correct |
7 ms |
296 KB |
Output is correct |
37 |
Correct |
3 ms |
324 KB |
Output is correct |
38 |
Correct |
20 ms |
208 KB |
Output is correct |
39 |
Correct |
15 ms |
208 KB |
Output is correct |
40 |
Correct |
14 ms |
208 KB |
Output is correct |
41 |
Correct |
14 ms |
292 KB |
Output is correct |
42 |
Correct |
14 ms |
312 KB |
Output is correct |
43 |
Correct |
17 ms |
208 KB |
Output is correct |
44 |
Correct |
17 ms |
296 KB |
Output is correct |
45 |
Correct |
13 ms |
208 KB |
Output is correct |
46 |
Correct |
17 ms |
304 KB |
Output is correct |
47 |
Correct |
20 ms |
208 KB |
Output is correct |
48 |
Correct |
14 ms |
308 KB |
Output is correct |
49 |
Correct |
17 ms |
308 KB |
Output is correct |
50 |
Correct |
16 ms |
208 KB |
Output is correct |
51 |
Correct |
15 ms |
316 KB |
Output is correct |
52 |
Correct |
17 ms |
312 KB |
Output is correct |
53 |
Correct |
17 ms |
312 KB |
Output is correct |
54 |
Correct |
17 ms |
308 KB |
Output is correct |
55 |
Correct |
15 ms |
296 KB |
Output is correct |
56 |
Correct |
15 ms |
208 KB |
Output is correct |
57 |
Correct |
11 ms |
208 KB |
Output is correct |
58 |
Correct |
15 ms |
300 KB |
Output is correct |
59 |
Correct |
8 ms |
316 KB |
Output is correct |
60 |
Correct |
13 ms |
336 KB |
Output is correct |
61 |
Correct |
12 ms |
308 KB |
Output is correct |
62 |
Correct |
17 ms |
304 KB |
Output is correct |
63 |
Correct |
13 ms |
320 KB |
Output is correct |