QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#377040#5434. Binary Substringsyingxue_catWA 1ms5420kbC++141.6kb2024-04-04 21:05:082024-04-04 21:05:09

Judging History

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

  • [2024-04-04 21:05:09]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5420kb
  • [2024-04-04 21:05:08]
  • 提交

answer

#include<bits/stdc++.h>
#define il inline
using namespace std;
il int read()
{
    int xr=0,F=1; char cr;
    while(cr=getchar(),cr<'0'||cr>'9') if(cr=='-') F=-1;
    while(cr>='0'&&cr<='9') 
        xr=(xr<<3)+(xr<<1)+(cr^48),cr=getchar();
    return xr*F;
}
const int N=2e5+5;
int n,k=1,vis[N],nxt[N];
vector<int> q,t;
void dfs(int x)
{
    vis[x]=1;
    if(!vis[(x<<1)%(1<<k)]) dfs((x<<1)%(1<<k));
    if(!vis[(x<<1|1)%(1<<k)]) dfs((x<<1|1)%(1<<k));
    q.push_back(x);
}
int main()
{
    n=read();
    if(n==1) {printf("1\n");return 0;}
    while((1<<k)<n-k) k++; k--;
    dfs(0); reverse(q.begin(),q.end());
    if((1<<k)==n-k+1) 
    {
        for(int i=1;i<k;i++) printf("0");for(auto x:q) printf("%d",x&1);
        printf("\n"); return 0;
    }
    memset(vis,0,sizeof(vis)),memset(nxt,-1,sizeof(nxt));
    q.push_back(0);
    for(int i=0;i+1<q.size();i++)
    {
        t.push_back(q[i]<<1|(q[i+1]&1));
        vis[t.back()]=1;
    }
    for(int i=0;i+1<t.size();i++) nxt[t[i]]=t[i+1]; nxt[t.back()]=*t.begin();
    // for(auto x:t) cout<<x<<" "; cout<<endl;
    for(int i=0;i<(1<<k+1);i++) if(nxt[i]==-1) nxt[i]=nxt[i^(1<<k)]^1;
    int len=q.size();
    for(int i=0;i<(1<<k+1);i++)
    {
        if(vis[i]) continue;
        int x=i;
        while(!vis[x]) vis[x]=1,x=nxt[x],len++;
        swap(nxt[i],nxt[i^(1<<k)]);
        if(len>=n-k)
        {
            for(int j=k;j>=0;j--) printf("%d",i>>j&1);
            x=nxt[i];
            for(int j=k+2;j<=n;j++) printf("%d",x&1),x=nxt[x];
            printf("\n"); return 0;
        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5420kb

input:

2

output:

10

result:

ok meet maximum 3

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 5308kb

input:

5

output:

00100

result:

wrong answer not meet maximum 11 < 12