QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#809898#3033. Harry Potter and the Palindromic Radiustarjen100 ✓2989ms26836kbC++202.2kb2024-12-11 18:05:592024-12-11 18:06:05

Judging History

This is the latest submission verdict.

  • [2024-12-11 18:06:05]
  • Judged
  • Verdict: 100
  • Time: 2989ms
  • Memory: 26836kb
  • [2024-12-11 18:05:59]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
struct ST
{
    char s[maxn * 2], str[maxn * 2];
    int Len[maxn * 2], len;
    void getstr()
    {
        int k = 0;
        len = strlen(s);
        str[k++] = 'A';
        for (int i = 0; i < len; i++)
        {
            str[k++] = '#';
            str[k++] = s[i];
        }
        str[k++] = '#';
        len = k;
        str[k] = 0;
    }
    int manacher()
    {
        getstr();
        int mx = 0, id;
        int maxx = 0;
        for (int i = 1; i < len; i++)
        {
            if (mx > i)
                Len[i] = min(mx - i, Len[2 * id - i]);
            else
                Len[i] = 1;
            while (str[i + Len[i]] == str[i - Len[i]])
                Len[i]++;
            if (Len[i] + i > mx)
            {
                mx = Len[i] + i;
                id = i;
                maxx = max(maxx, Len[i]);
            }
        }
        // printf("%s\n", str);
        // for (int i = 0; i <= len; i++)
        //     cout << Len[i] << " ";
        // cout << endl;
        return (maxx - 1);
    }
} sol;
void solve()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    vector<int> g(n);
    for (int i = 1; i < n; i++)
    {
        int p = (a[i] == 0);
        if (i + 1 < n)
            g[i + 1] = p;
    }
    vector<string> ans;
    for (g[0] = 0; g[0] < 2; g[0]++)
    {
        for (g[1] = 0; g[1] < 2; g[1]++)
        {
            sol.s[0] = g[0] + '0';
            sol.s[1] = g[1] + '0';
            for (int i = 2; i < n; i++)
                sol.s[i] = ((sol.s[i - 2] - '0') ^ g[i]) + '0';
            sol.s[n] = 0;
            sol.manacher();
            int flag = 1;
            for (int i = 0; i < n; i++)
            {
                flag &= (sol.Len[(i + 1) * 2] / 2 - 1 == a[i]);
            }
            if (flag)
                ans.emplace_back(string(sol.s, sol.s + n));
        }
    }
    cout << ans.size() << "\n";
    for (auto it : ans)
        cout << it << "\n";
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T;
    cin >> T;
    while (T--)
        solve();
}

Details

Tip: Click on the bar to expand more detailed information

Pretests


Final Tests

Test #1:

score: 100
Accepted
time: 2989ms
memory: 26836kb

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