QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#281702#3033. Harry Potter and the Palindromic RadiusDualqwq#0 0ms0kbC++201.8kb2023-12-10 15:57:362023-12-10 15:57:36

Judging History

This is the latest submission verdict.

  • [2023-12-10 15:57:36]
  • Judged
  • Verdict: 0
  • Time: 0ms
  • Memory: 0kb
  • [2023-12-10 15:57:36]
  • Submitted

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 dif[N],vis[N],co[N],bel[N];
bool FLG = true;
void dfsc(int x,int fa,int st) {
	vis[x] = true;bel[x] = st;
	for(int i = fir[x],y;y = to[i],i;i = nxt[i])
		if(!vis[y]) dif[y] = dif[x] ^ w[i],dfsc(y,x,st);
		else if((dif[y] ^ dif[x]) != w[i]) FLG = false;
}
vector<vector<int> > Ans;
void dfs2(int x) {
	if(x == rts.size()) {
		vector<int> res(n + 1);
		for(int i = 1;i <= n;i++) res[i] = co[bel[i]] ^ dif[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] = dif[i] = co[i] = 0;
	FLG = true;
	for(int i = 1;i <= n;i++) if(!vis[i]) dfsc(i,0,i),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...

result: