QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#235521#3033. Harry Potter and the Palindromic Radiussidlee#0 0ms0kbC++141.9kb2023-11-02 21:14:532023-11-02 21:14:53

Judging History

This is the latest submission verdict.

  • [2023-11-02 21:14:53]
  • Judged
  • Verdict: 0
  • Time: 0ms
  • Memory: 0kb
  • [2023-11-02 21:14:53]
  • Submitted

answer

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define pb push_back
#define st first
#define nd second

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++)
    {
        if(i>hi)
            ans[i]=0;
        else
            ans[i]=min(hi-i,ans[hi-i+lo]);
        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];
        for(int k=0; k<4; k++)
        {
            sth[k][0]=k/2;
            sth[k][1]=k%2;
            for(int i=2; i<n; i+=2)
            {
                if(p[i-1]!=0)
                    sth[k][i]=sth[k][i-2];
                else
                    sth[k][i]=!sth[k][i-2];
            }
            for(int i=3; i<n; i+=2)
            {
                if(p[i-1]!=0)
                    sth[k][i]=sth[k][i-2];
                else
                    sth[k][i]=!sth[k][i-2];
            }
            manacher(k);
            ok[k]=1;
            for(int i=0; i<n; i++)
            {
                if(p[i]!=ans[i])
                {
                    ok[k]=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
Time Limit Exceeded

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
0
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
0
4
001
011
100
110
0
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
0001
0100
...

result: