QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#377056#5434. Binary Substringsyingxue_catRE 1ms5476kbC++141.7kb2024-04-04 21:11:302024-04-04 21:11:31

Judging History

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

  • [2024-04-04 21:11:31]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:5476kb
  • [2024-04-04 21:11:30]
  • 提交

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--;
    cerr<<"k= "<<k<<endl;
    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();
    // cout<<nxt[t.back()]<<endl;
    // 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=t.size();
    for(int i=0;i<(1<<k+1);i++)
    {
        if(vis[i]) continue;
        // cout<<"qwq "<<i<<" "<<nxt[i]<<endl;
        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;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3844kb

input:

2

output:

01

result:

ok meet maximum 3

Test #2:

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

input:

5

output:

00110

result:

ok meet maximum 12

Test #3:

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

input:

1

output:

1

result:

ok meet maximum 1

Test #4:

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

input:

3

output:

001

result:

ok meet maximum 5

Test #5:

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

input:

4

output:

0010

result:

ok meet maximum 8

Test #6:

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

input:

6

output:

000110

result:

ok meet maximum 16

Test #7:

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

input:

7

output:

0001100

result:

ok meet maximum 21

Test #8:

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

input:

8

output:

01000110

result:

ok meet maximum 27

Test #9:

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

input:

9

output:

010001101

result:

ok meet maximum 34

Test #10:

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

input:

10

output:

0001011100

result:

ok meet maximum 42

Test #11:

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

input:

11

output:

00001011100

result:

ok meet maximum 50

Test #12:

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

input:

12

output:

000010111000

result:

ok meet maximum 59

Test #13:

score: -100
Runtime Error

input:

200000

output:


result: