QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#233427 | #3033. Harry Potter and the Palindromic Radius | jerzyk# | 0 | 0ms | 0kb | C++20 | 1.1kb | 2023-10-31 17:32:39 | 2023-10-31 17:32:40 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
vector<int> manacher_odd(string s) {
int n = s.size();
s = "$" + s + "^";
vector<int> p(n + 2);
for(int i = 1; i <= n; i++) {
while(s[i - p[i]] == s[i + p[i]]) {
p[i]++;
}
}
return vector<int>(begin(p) + 1, end(p) - 1);
}
void solve() {
int n;
cin >> n;
vector<int>V(n), ans(n);
rep(i, n) cin >> V[i];
for(int i=1; i<n-1; ++i)
if(V[i]) ans[i+1]=ans[i-1]; else ans[i+1]=ans[i-1]^1;
string s;
rep(i, n) if(ans[i]) s+="1"; else s+="0";
vector<int>P=manacher_odd(s);
rep(i, n) if(V[i]!=P[i]-1) {
cout << 0 << '\n';
return;
}
cout << 4 << '\n';
rep(a, 2) rep(b, 2) {
rep(i, n) {
int x=ans[i];
if(i%2==0) x^=a; else x^=b;
cout << x;
}
cout << '\n';
}
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int _=1;
cin >> _;
while(_--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
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 ...