QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#235461#3033. Harry Potter and the Palindromic Radiussidlee#0 0ms0kbC++143.7kb2023-11-02 19:48:112023-11-02 19:48:12

Judging History

This is the latest submission verdict.

  • [2023-11-02 19:48:12]
  • Judged
  • Verdict: 0
  • Time: 0ms
  • Memory: 0kb
  • [2023-11-02 19:48:11]
  • Submitted

answer

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int p[1001000];
bool ok[4];
bool sth[4][1001000];
int ans[1001000];
int n;

void manacher(int x)
{
    for(int i=0; i<n; i++)
    {
        ans[i]=0;
    }
    int lo=0,hi=0;
    for(int i=1; i<n-1; i++)
    {
        ans[i]=min(hi-i,ans[hi-i+lo]);
        // if(x==0)
        //     cout<<i<<" "<<ans[i]<<" "<<sth[x][i-ans[i]-1]<<" "<<sth[x][i+ans[i]+1]<<"\n";
        while(i-ans[i]-1>=0 && i+ans[i]+1<n && sth[x][i-ans[i]-1] == sth[x][i+ans[i]+1])
            ++ans[i];
        if(i+ans[i]>i)
        {
            lo=i-ans[i];
            hi=i+ans[i];
        }
    }
}

int main()
{
    // cin.tie(0);
    // ios_base::sync_with_stdio(0);
    int tst;
    cin>>tst;
    while(tst--)
    {
        cin>>n;
        for(int i=0; i<n; i++)
            cin>>p[i];
        sth[0][0]=0;
        sth[0][1]=0;
        for(int i=2; i<n; i+=2)
        {
            if(p[i-1]!=0)
                sth[0][i]=sth[0][i-2];
            else
                sth[0][i]=!sth[0][i-2];
        }
        for(int i=3; i<n; i+=2)
        {
            if(p[i-1]!=0)
                sth[0][i]=sth[0][i-2];
            else
                sth[0][i]=!sth[0][i-2];
        }
        // for(int i=0; i<n; i++)
        //     cout<<sth[0][i];
        // cout<<"\n";
        manacher(0);
        ok[0]=1;
        for(int i=0; i<n; i++)
        {
            // cout<<p[i]<<" "<<ans[i]<<"\n";
            if(p[i]!=ans[i])
            {
                ok[0]=0;
                break;
            }
        }
        // cout<<"WTHHESWT???\n";
        

        sth[1][0]=0;
        sth[1][1]=1;
        for(int i=2; i<n; i+=2)
        {
            if(p[i-1]!=0)
                sth[1][i]=sth[1][i-2];
            else
                sth[1][i]=!sth[1][i-2];
        }
        for(int i=3; i<n; i+=2)
        {
            if(p[i-1]!=0)
                sth[1][i]=sth[1][i-2];
            else
                sth[1][i]=!sth[1][i-2];
        }
        manacher(1);
        ok[1]=1;
        for(int i=1; i<n; i++)
            if(p[i]!=ans[i])
            {
                ok[1]=0;
                break;
            }
        
        
        sth[2][0]=1;
        sth[2][1]=0;
        for(int i=2; i<n; i+=2)
        {
            if(p[i-1]!=0)
                sth[2][i]=sth[2][i-2];
            else
                sth[2][i]=!sth[2][i-2];
        }
        for(int i=3; i<n; i+=2)
        {
            if(p[i-1]!=0)
                sth[2][i]=sth[2][i-2];
            else
                sth[2][i]=!sth[2][i-2];
        }
        manacher(2);
        ok[2]=1;
        for(int i=0; i<n; i++)
            if(p[i]!=ans[i])
            {
                ok[2]=0;
                break;
            }


        sth[3][0]=1;
        sth[3][1]=1;
        for(int i=2; i<n; i+=2)
        {
            if(p[i-1]!=0)
                sth[3][i]=sth[3][i-2];
            else
                sth[3][i]=!sth[3][i-2];
        }
        for(int i=3; i<n; i+=2)
        {
            if(p[i-1]!=0)
                sth[3][i]=sth[3][i-2];
            else
                sth[3][i]=!sth[3][i-2];
        }
        manacher(3);
        ok[3]=1;
        for(int i=0; i<n; i++)
            if(p[i]!=ans[i])
            {
                ok[3]=0;
                break;
            }

        int res=0;
        for(int i=0;i<4; i++)
            if(ok[i])
                res++;
        cout<<res<<"\n";
        for(int i=0; i<4; i++)
        {
            if(ok[i])
            {
                for(int j=0; j<n; j++)
                    cout<<sth[i][j];
                cout<<"\n";
            }
        }
    }
}

詳細信息

Test #1:

score: 0
Runtime Error

input:

131112
2
0 0
2
0 1
2
0 0
2
1 0
2
0 0
2
0 1
2
0 0
2
0 1
3
0 1 0
3
0 1 1
3
0 0 0
3
0 1 0
3
0 1 0
3
0 2 0
3
0 0 0
3
1 0 0
3
0 0 0
3
1 0 0
3
0 1 0
3
0 2 0
3
0 0 0
3
0 0 1
3
0 1 0
3
0 2 0
4
0 1 1 0
4
0 1 2 0
4
0 0 1 0
4
0 0 1 1
4
0 1 0 0
4
0 1 0 1
4
0 0 0 0
4
0 0 1 0
4
0 0 1 0
4
1 0 1 0
4
0 1 1 0
4
0 1 2...

output:

4
00
01
10
11
0
4
00
01
10
11
1
01
4
00
01
10
11
0
4
00
01
10
11
0
4
000
010
101
111
0
4
001
011
100
110
4
000
010
101
111
4
000
010
101
111
0
4
001
011
100
110
1
011
4
001
011
100
110
1
011
4
000
010
101
111
0
4
001
011
100
110
0
4
000
010
101
111
0
4
0000
0101
1010
1111
0
4
0010
0111
1000
1101
0
4...

result: