#include "ancient2.h"
#include<bits/stdc++.h>
using namespace std;
const int maxn=1005;
int n;
bitset<maxn> bs[maxn],cur;
bool ok[maxn];
bool add(int t=1){
for(int i=n;i>=1;i--){
if(cur[i]){
if(!ok[i]){
if(t) bs[i]=cur,ok[i]=true;
return true;
}
else cur^=bs[i];
}
}
return false;
}
void cal_first(int x){
for(int i=0;i<x;i++){
cur.reset();
vector<int> a(i+3),b(i+3);
for(int j=0;j<i;j++) a[j]=b[j]=j+1;
a[i]=i+1;b[i]=i+2;
a[i+1]=b[i+1]=i+1;
a[i+2]=b[i+2]=i+2;
int d=Query(i+3,a,b)-i-1;
cur[i+1]=1;cur[0]=d;
add();
}
}
bool check(string s){
int sz=(int)s.size();
vector<int> kmp(sz+1,-1);
vector<int> a(sz+1),b(sz+1);
for(int i=1;i<=sz;i++){
int j=kmp[i-1];
while(j>=0 && s[j]!=s[i-1]) j=kmp[j];
kmp[i]=j+1;
}
vector<vector<int>> nxt(sz+1,vector<int>(2,0));
for(int i=0;i<=sz;i++){
int j=kmp[i];
for(int k=0;k<2;k++){
if(i<sz && (s[i]-'0')==k) nxt[i][k]=i+1;
else if(j!=-1) nxt[i][k]=nxt[j][k];
}
a[i]=nxt[i][0];b[i]=nxt[i][1];
}
if(Query(sz+1,a,b)!=sz) return false;
else return true;
}
void cal_last(int x){
string s;
for(int i=n;i>n-x;i--){
s='0'+s;
if(!check(s)) s[0]='1';
cur.reset();
cur[i]=1;cur[0]=s[0]-'0';
add();
}
}
void cal_mid(int x){
for(int i=1;i<=51;i++){
for(int j=0;j<i;j++){
cur.reset();
for(int k=0;k<n;k++) if(k%i==j) cur[k+1]=1;
if(!add(0)) continue;
cur.reset();
for(int k=0;k<n;k++) if(k%i==j) cur[k+1]=1;
vector<int> a(2*i),b(2*i);
for(int k=0;k<i;k++){
if(k!=j){
a[k]=b[k]=(k+1)%i;
a[i+k]=b[i+k]=i+(k+1)%i;
}
else{
a[k]=b[i+k]=(k+1)%i;
b[k]=a[i+k]=i+(k+1)%i;
}
}
int d=Query(2*i,a,b);
//cout << i << ' ' << j << ' ' << (d>=i) << '\n';
cur[0]=(d>=i);
add();x--;
if(x==0) return;
}
}
}
string Solve(int N) {
n=N;
cal_first(100);
cal_last(101);
cal_mid(799);
string res;
for(int i=1;i<=N;i++){
cur.reset();cur[i]=1;
for(int j=i;j>=1;j--) if(cur[j]) cur^=bs[j];
int d=cur[0];
res+=char('0'+d);
}
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
452 KB |
Output is correct |
2 |
Correct |
40 ms |
404 KB |
Output is correct |
3 |
Correct |
35 ms |
412 KB |
Output is correct |
4 |
Correct |
43 ms |
424 KB |
Output is correct |
5 |
Correct |
47 ms |
444 KB |
Output is correct |
6 |
Correct |
37 ms |
420 KB |
Output is correct |
7 |
Correct |
36 ms |
436 KB |
Output is correct |
8 |
Correct |
41 ms |
424 KB |
Output is correct |
9 |
Correct |
45 ms |
396 KB |
Output is correct |
10 |
Correct |
38 ms |
432 KB |
Output is correct |
11 |
Correct |
38 ms |
440 KB |
Output is correct |
12 |
Correct |
41 ms |
412 KB |
Output is correct |
13 |
Correct |
42 ms |
408 KB |
Output is correct |
14 |
Correct |
37 ms |
436 KB |
Output is correct |
15 |
Correct |
36 ms |
440 KB |
Output is correct |
16 |
Correct |
44 ms |
448 KB |
Output is correct |
17 |
Correct |
45 ms |
448 KB |
Output is correct |
18 |
Correct |
44 ms |
436 KB |
Output is correct |
19 |
Correct |
48 ms |
492 KB |
Output is correct |
20 |
Correct |
36 ms |
440 KB |
Output is correct |
21 |
Correct |
43 ms |
380 KB |
Output is correct |
22 |
Correct |
38 ms |
400 KB |
Output is correct |
23 |
Correct |
38 ms |
400 KB |
Output is correct |
24 |
Correct |
38 ms |
396 KB |
Output is correct |
25 |
Correct |
37 ms |
448 KB |
Output is correct |
26 |
Correct |
38 ms |
424 KB |
Output is correct |
27 |
Correct |
34 ms |
408 KB |
Output is correct |
28 |
Correct |
38 ms |
452 KB |
Output is correct |
29 |
Correct |
43 ms |
424 KB |
Output is correct |
30 |
Correct |
37 ms |
456 KB |
Output is correct |
31 |
Correct |
38 ms |
424 KB |
Output is correct |
32 |
Correct |
42 ms |
548 KB |
Output is correct |
33 |
Correct |
40 ms |
528 KB |
Output is correct |
34 |
Correct |
37 ms |
400 KB |
Output is correct |
35 |
Correct |
44 ms |
516 KB |
Output is correct |
36 |
Correct |
36 ms |
444 KB |
Output is correct |
37 |
Correct |
48 ms |
428 KB |
Output is correct |
38 |
Correct |
39 ms |
448 KB |
Output is correct |
39 |
Correct |
46 ms |
448 KB |
Output is correct |
40 |
Correct |
38 ms |
440 KB |
Output is correct |
41 |
Correct |
36 ms |
384 KB |
Output is correct |
42 |
Correct |
43 ms |
660 KB |
Output is correct |
43 |
Correct |
50 ms |
392 KB |
Output is correct |
44 |
Correct |
45 ms |
408 KB |
Output is correct |
45 |
Correct |
37 ms |
456 KB |
Output is correct |
46 |
Correct |
38 ms |
432 KB |
Output is correct |
47 |
Correct |
37 ms |
400 KB |
Output is correct |
48 |
Correct |
36 ms |
432 KB |
Output is correct |
49 |
Correct |
41 ms |
416 KB |
Output is correct |
50 |
Correct |
39 ms |
388 KB |
Output is correct |
51 |
Correct |
39 ms |
536 KB |
Output is correct |
52 |
Correct |
37 ms |
436 KB |
Output is correct |
53 |
Correct |
36 ms |
384 KB |
Output is correct |
54 |
Correct |
34 ms |
456 KB |
Output is correct |
55 |
Correct |
38 ms |
420 KB |
Output is correct |
56 |
Correct |
36 ms |
444 KB |
Output is correct |
57 |
Correct |
39 ms |
440 KB |
Output is correct |
58 |
Correct |
35 ms |
424 KB |
Output is correct |
59 |
Correct |
42 ms |
456 KB |
Output is correct |
60 |
Correct |
42 ms |
448 KB |
Output is correct |
61 |
Correct |
42 ms |
400 KB |
Output is correct |
62 |
Correct |
35 ms |
440 KB |
Output is correct |
63 |
Correct |
37 ms |
456 KB |
Output is correct |