QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#494852 | #3033. Harry Potter and the Palindromic Radius | PetroTarnavskyi# | 100 ✓ | 1829ms | 17648kb | C++20 | 1.8kb | 2024-07-27 17:16:36 | 2024-07-27 17:16:40 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;
const int N = 1 << 20;
int col[N];
VI comps[2];
string ans;
void solve()
{
int n;
cin >> n;
VI p(n);
FOR(i, 0, n)
{
cin >> p[i];
p[i]++;
}
FOR(i, 0, n)
{
if (i - p[i] + 1 < 0 || i + p[i] - 1 >= n)
{
cout << "0\n";
return;
}
}
FOR(i, 0, 2)
comps[i].clear();
col[0] = col[1] = 0;
FOR(i, 0, n)
{
if(i >= 2)
{
if(p[i - 1] == 1)
col[i] = col[i - 2] ^ 1;
else
col[i] = col[i - 2];
}
comps[i % 2].PB(i);
}
int l = -1, r = -1;
FOR(i, 0, n)
{
int cur = 0;
if (i <= r)
cur = min(r - i + 1, p[l + (r - i)]);
if (cur > p[i])
{
cout << "0\n";
return;
}
while (cur < p[i])
{
if(cur > 0)
{
if(col[i - cur] != col[i + cur])
{
cout << "0\n";
return;
}
}
cur++;
}
if (0 <= i - cur && i + cur < n)
{
if(col[i - cur] == col[i + cur])
{
cout << "0\n";
return;
}
}
if (i + cur - 1 > r)
{
r = i + cur - 1;
l = i - cur + 1;
}
}
int cntComps = 2;
cout << (1 << cntComps) << "\n";
ans.resize(n);
FOR(mask, 0, 1 << cntComps)
{
FOR(i, 0, cntComps)
{
int b = (mask >> (cntComps - 1 - i)) & 1;
for (int v : comps[i])
{
ans[v] = (col[v] ^ b) + '0';
}
}
cout << ans << "\n";
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Pretests
Final Tests
Test #1:
score: 100
Accepted
time: 1829ms
memory: 17648kb
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