QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#398628 | #5434. Binary Substrings | dengziyue | WA | 2ms | 8256kb | C++14 | 1.3kb | 2024-04-25 15:56:56 | 2024-04-25 15:57:01 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define max_n 900000
int n;
int m;
int lim;
int a[max_n+2],ai=0;
bool vis[max_n+2];
int to[max_n+2];
void dfs(int u){
a[++ai]=u; vis[u]=true;
if(u==20){printf("pay attention\n");}
for(int i=1,v;i>=0;--i){
v=(u<<1|i)&((1<<m)-1);
if(!vis[v])dfs(v);
}
}
int main(){
#ifndef ONLINE_JUDGE
freopen("QOJ5434_1.in","r",stdin);
freopen("QOJ5434_1.out","w",stdout);
#endif
scanf("%d",&n);
if(n==1){printf("0\n"); return 0;}
if(n==2){printf("01\n"); return 0;}
if(n==3){printf("010\n"); return 0;}
for(int i=1;i<=20;++i){
if((1<<i)<=n-i+1)m=i;
}
dfs(0);
if(n==(1<<m)+m-1){
for(int i=1;i<=ai;++i)printf("%d",a[i]&1);
for(int i=1;i<m;++i)printf("%d",0);
return 0;
}
for(int i=1;i<=ai;++i)a[i]=a[i]<<1|(a[i+1]&1);
memset(vis,0,sizeof(vis));
for(int i=1;i<=ai;++i)vis[a[i]]=true;
memset(to,-1,sizeof(to));
for(int i=1;i<=ai;++i)to[a[i]]=a[i%ai+1];
for(int x=0;x<(1<<(m+1));++x){
if(to[x]==-1)to[x]=to[x^(1<<m)]^1;
}
for(int x=1;x<(1<<(m+1));++x){
if(vis[x])continue;
for(int u=x;!vis[u];u=to[u]){vis[u]=true; ++ai;}
swap(to[x],to[x^(1<<m)]);
if(m+ai>=n){
for(int i=m;i>=1;--i)printf("%d",(to[x]>>i)&1);
int u=to[x];
for(int i=m+1;i<=n;++i,u=to[u])printf("%d",u&1);
return 0;
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3664kb
input:
2
output:
01
result:
ok meet maximum 3
Test #2:
score: 0
Accepted
time: 1ms
memory: 5812kb
input:
5
output:
01100
result:
ok meet maximum 12
Test #3:
score: 0
Accepted
time: 0ms
memory: 3796kb
input:
1
output:
0
result:
ok meet maximum 1
Test #4:
score: 0
Accepted
time: 0ms
memory: 3664kb
input:
3
output:
010
result:
ok meet maximum 5
Test #5:
score: 0
Accepted
time: 0ms
memory: 8228kb
input:
4
output:
1011
result:
ok meet maximum 8
Test #6:
score: 0
Accepted
time: 1ms
memory: 8120kb
input:
6
output:
100110
result:
ok meet maximum 16
Test #7:
score: 0
Accepted
time: 1ms
memory: 8256kb
input:
7
output:
1001101
result:
ok meet maximum 21
Test #8:
score: 0
Accepted
time: 0ms
memory: 8120kb
input:
8
output:
10011010
result:
ok meet maximum 27
Test #9:
score: 0
Accepted
time: 2ms
memory: 8160kb
input:
9
output:
110100111
result:
ok meet maximum 34
Test #10:
score: -100
Wrong Answer
time: 0ms
memory: 5940kb
input:
10
output:
0111010000
result:
wrong answer not meet maximum 41 < 42