QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#377042#5434. Binary Substringsyingxue_catWA 1ms5372kbC++141.6kb2024-04-04 21:06:332024-04-04 21:06:33

Judging History

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

  • [2024-04-04 21:06:33]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5372kb
  • [2024-04-04 21:06:33]
  • 提交

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+1) 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: 0ms
memory: 3808kb

input:

2

output:

01

result:

ok meet maximum 3

Test #2:

score: 0
Accepted
time: 0ms
memory: 3760kb

input:

5

output:

00110

result:

ok meet maximum 12

Test #3:

score: 0
Accepted
time: 0ms
memory: 3760kb

input:

1

output:

1

result:

ok meet maximum 1

Test #4:

score: 0
Accepted
time: 1ms
memory: 5372kb

input:

3

output:

001

result:

ok meet maximum 5

Test #5:

score: 0
Accepted
time: 0ms
memory: 5360kb

input:

4

output:

0010

result:

ok meet maximum 8

Test #6:

score: 0
Accepted
time: 1ms
memory: 5304kb

input:

6

output:

000110

result:

ok meet maximum 16

Test #7:

score: 0
Accepted
time: 1ms
memory: 5288kb

input:

7

output:

0001100

result:

ok meet maximum 21

Test #8:

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

input:

8

output:

00011000

result:

wrong answer not meet maximum 26 < 27