QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#235373 | #3033. Harry Potter and the Palindromic Radius | szaranczuk# | 0 | 0ms | 0kb | C++17 | 3.2kb | 2023-11-02 18:22:29 | 2024-01-17 03:33:53 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define st first
#define nd second
using ll = long long;
using pii = pair<int,int>;
const int N = 1e6 + 5;
int n;
int w[N];
int w2[N];
vector<pii> adj[N];
int cnt;
bool vis[N];
int col[N];
int cmp[N];
bool ans;
char ans2[N];
vector<string> ans3;
bool dfs(int v, int c){
vis[v] = true;
col[v] = c;
cmp[v] = cnt;
for(auto& [u, w] : adj[v]){
if(vis[u]){
if(col[u] != col[v] ^ w){
return false;
}
}
else{
if(!dfs(u, c^w)){
return false;
}
}
}
return true;
}
int main(){
cin.tie(0);
ios_base::sync_with_stdio(0);
int t;
cin >> t;
while(t--) {
cin >> n;
for(int i=0;i<n;i++){
adj[i].clear();
}
fill(w2,w2+n,0);
ans = true;
for(int i=0;i<n;i++){
cin >> w[i];
}
int l=0,r=0;
for(int i=1;i<n-1;i++){
if(i != 1) w2[i] = min(r-i, w2[r-i+l]);
while(i-w2[i]-1 >= 0 && i+w2[i]+1 < n && w2[i] < w[i]){
adj[i-w2[i]-1].emplace_back(i+w2[i]+1, 0);
adj[i+w2[i]+1].emplace_back(i-w2[i]-1, 0);
w2[i]++;
}
if(i-w2[i]-1 >= 0 && i+w2[i]+1 < n){
adj[i-w2[i]-1].emplace_back(i+w2[i]+1, 1);
adj[i+w2[i]+1].emplace_back(i-w2[i]-1, 1);
}
if(i+w2[i] > r){
l = i-w2[i], r = i+w2[i];
}
}
cnt = 0;
fill(vis,vis+n,0);
fill(col,col+n,0);
fill(cmp,cmp+n,0);
ans = true;
for(int i=0;i<n;i++){
if(!vis[i]){
ans &= dfs(i, 0);
cnt++;
}
}
if(!ans){
cout << "0\n";
}
else{
for(int i=0;i<n;i++){
cmp[i] = cnt-1-cmp[i];
}
ans3.clear();
for(int m=0;m<(1<<cnt);m++){
for(int i=0;i<n;i++){
ans2[i] = char('0' + ((m>>cmp[i]&1)^(col[i])));
}
l = 0, r = 0;
fill(w2,w2+n,0);
for(int i=0;i<n;i++){
if(i > 0){
w2[i] = min(r-i, w2[r-i+l]);
while(i-w2[i]-1 >= 0 && i+w2[i]+1 < n && ans2[i-w2[i]-1] == ans2[i+w2[i]+1]) w2[i]++;
if(i+w2[i] > r){
l = i-w2[i], r = i+w2[i];
}
}
}
bool chk = true;
for(int i=0;i<n;i++){
chk &= w[i] == w2[i];
}
if(chk){
string s;
for(int i=0;i<n;i++){
s += ans2[i];
}
ans3.push_back(s);
}
}
cout << ans3.size() << "\n";
for(auto v : ans3){
cout << v << "\n";
}
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Memory 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 ...