QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#78378#5434. Binary Substringszjy0001WA 2ms5444kbC++141.3kb2023-02-18 13:07:572023-02-18 13:08:00

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-18 13:08:00]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:5444kb
  • [2023-02-18 13:07:57]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
inline int read(){
	int x=0,f=1;char ch;
	while(!isdigit(ch=getchar()))if(ch=='-')f=-f;
	do x=(x<<3)+(x<<1)+(ch^48);while(isdigit(ch=getchar()));
	return x*f;
}
const int N=1e6+5;
int n,k,S,T,len;
int vis[N],nxt[N],ans[N];
void run(int x){
    if(!vis[x])
        vis[x]=1,
        run((x<<1)%S),run((x<<1|1)%S),
        ans[++len]=x;
}
signed main(){
    n=read();
    if(n==1){
        puts("0");
        return 0;
    }
    for(;(1<<k)+k-1<=n;++k);--k;
    S=1<<k,T=S<<1;
    run(0);
    reverse(ans+1,ans+len+1);
    if(n==(1<<k)+k-1){
        for(int i=1;i<k;++i)putchar('0');
        for(int i=1;i<=len;++i)putchar('0'+(ans[i]&1));
        return 0;
    }
    for(int i=0;i<T;++i)vis[i]=0,nxt[i]=-1;
    for(int i=1;i<=len;++i)
        vis[ans[i]=(ans[i]<<1)|(ans[i+1]&1)]=1;
    for(int i=1;i<=len;++i)nxt[ans[i]]=ans[i%len+1];
    for(int i=0;i<T;++i)
        if(nxt[i]==-1)ans[i]=ans[i^S]^1;
    for(int i=0;i<T;++i)
    if(!vis[i]){
        for(int j=i;!vis[j];j=nxt[j])vis[j]=1,++len;
        swap(nxt[i],nxt[i^S]);
        if(len+k>=n){
            for(int j=k;~j;--j)putchar('0'+((nxt[i]>>j)&1));
            for(int j=k+2,l=nxt[nxt[i]];j<=n;++j,l=nxt[l])
                putchar('0'+(l&1));
            break;
        }
    }
	return 0;
}
/*

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3316kb

input:

2

output:

01

result:

ok meet maximum 3

Test #2:

score: 0
Accepted
time: 2ms
memory: 3472kb

input:

5

output:

00110

result:

ok meet maximum 12

Test #3:

score: 0
Accepted
time: 2ms
memory: 3368kb

input:

1

output:

0

result:

ok meet maximum 1

Test #4:

score: 0
Accepted
time: 2ms
memory: 5444kb

input:

3

output:

010

result:

ok meet maximum 5

Test #5:

score: -100
Wrong Answer
time: 2ms
memory: 5384kb

input:

4

output:

0101

result:

wrong answer not meet maximum 7 < 8