QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#281701 | #3033. Harry Potter and the Palindromic Radius | Dualqwq# | 0 | 0ms | 0kb | C++20 | 1.8kb | 2023-12-10 15:54:10 | 2023-12-10 15:54:11 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5,M = 1e7 + 5;
int n,R[N];
int fir[N],nxt[M],to[M],w[M],ect = 1;
inline void addedge(int u1,int v1,int w1) {
// printf("Es:%d,%d,%d\n",u1,v1,w1);
nxt[++ect] = fir[u1];fir[u1] = ect;to[ect] = v1;w[ect] = w1;
}
vector<int> rts;
int co[N],vis[N];
bool FLG = true;
void dfsc(int x,int fa) {
vis[x] = true;
for(int i = fir[x],y;y = to[i],i;i = nxt[i])
if(!vis[y]) co[y] = co[x] ^ w[i],dfsc(y,x);
else if((co[y] ^ co[x]) != w[i]) FLG = false;
}
vector<vector<int> > Ans;
void dfs2(int x) {
if(x == rts.size()) {
for(int i = 1;i <= n;i++) vis[i] = 0;
for(auto i : rts)
dfsc(i,0);
vector<int> res(n + 1);
for(int i = 1;i <= n;i++) res[i] = co[i];
Ans.push_back(res);
return;
}
co[rts[x]] = 0;
dfs2(x + 1);
co[rts[x]] = 1;
dfs2(x + 1);
}
inline void work() {
cin >> n;
for(int i = 1;i <= n;i++) cin >> R[i],++R[i];
ect = 1;
for(int i = 1;i <= n;i++) fir[i] = 0;
rts.clear();
int tl = 0,tr = 0;
for(int i = 1;i <= n;i++) {
int lim = tr >= i ? min(tr - i + 1,R[2 * tl - i]) : 0;
if(lim > R[i]) return puts("0"),void();
for(int j = lim + 1;j < R[i];j++)
addedge(i - j,i + j,0),addedge(i + j,i - j,0);
if(i - R[i] >= 1 && i + R[i] <= n) addedge(i - R[i],i + R[i],1),addedge(i + R[i],i - R[i],1);
if(i + R[i] - 1 >= tr) tl = i,tr = i + R[i] - 1;
}
// puts("done");
rts.clear();
for(int i = 1;i <= n;i++) vis[i] = 0;
FLG = true;
for(int i = 1;i <= n;i++) if(!vis[i]) dfsc(i,0),rts.push_back(i);
if(!FLG) return puts("0"),void();
Ans.clear();
dfs2(0);
sort(Ans.begin(),Ans.end());
printf("%d\n",(int)Ans.size());
for(auto it : Ans)
for(int i = 1;i <= n;i++)
printf("%d",it[i]),i == n ? (void)putchar('\n') : void();
}
int main() {
int T;
cin >> T;
while(T--) work();
return 0;
}
詳細信息
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 4 00 01 10 11 4 00 01 10 11 4 00 01 10 11 4 00 01 10 11 4 00 01 10 11 4 00 01 10 11 4 00 01 10 11 4 000 010 101 111 4 000 010 101 111 4 001 011 100 110 4 000 010 101 111 4 000 010 101 111 4 000 010 101 111 4 001 011 100 110 4 001 011 100 110 4 001 011 100 110 4 001 011 100 110 4 000 01...