QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#235537#3033. Harry Potter and the Palindromic Radiussidlee#100 ✓11228ms30516kbC++142.1kb2023-11-02 21:34:432023-11-02 21:34:44

Judging History

This is the latest submission verdict.

  • [2023-11-02 21:34:44]
  • Judged
  • Verdict: 100
  • Time: 11228ms
  • Memory: 30516kb
  • [2023-11-02 21:34:43]
  • 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];
vector<int> ans;
int n;

void manacher(int x)
{
    ans.clear();
    vector<char> s;
    s.push_back('@');
    for(int i=0; i<n; i++)
    {
        s.push_back(sth[x][i]);
        s.push_back('#');
    }
    s.back()='&';
    int lo=0,hi=0;
    ans.resize(s.size()-1);
    for(int i=1; i<int(s.size())-1; i++)
    {
        if(i!=1)
            ans[i]=min(hi-i,ans[hi-i+lo]);
        while(s[i-ans[i]-1] == s[i+ans[i]+1])
        {
            ++ans[i];
        }
        if(i+ans[i] > hi)
        {
            lo=i-ans[i];
            hi=i+ans[i];
        }
    }
    ans.erase(ans.begin());
    for(int i=0; i<int(ans.size()); i++)
    {
        if(i%2==ans[i]%2)
            ++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((ans[2*i]-1)/2!=p[i])
                    ok[k]=0;
            }
        }
        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";
            }
        }
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 11228ms
memory: 30516kb

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:

ok 401208 lines