QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#233447 | #3033. Harry Potter and the Palindromic Radius | jerzyk# | 100 ✓ | 2149ms | 23812kb | C++20 | 1.2kb | 2023-10-31 17:43:49 | 2023-10-31 17:43:49 |
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);
int l = 1, r = 1;
for(int i = 1; i <= n; i++) {
p[i] = max(0, min(r - i, p[l + (r - i)]));
while(s[i - p[i]] == s[i + p[i]]) {
p[i]++;
}
if(i + p[i] > r) {
l = i - p[i], r = 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) {
s="";
rep(i, n) {
int x=ans[i];
if(i%2==0) x^=a; else x^=b;
if(x) s+="1"; else s+="0";
}
cout << s << '\n';
}
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int _=1;
cin >> _;
while(_--) solve();
}
詳細信息
Test #1:
score: 100
Accepted
time: 2149ms
memory: 23812kb
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