QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#281796#3033. Harry Potter and the Palindromic RadiusDualqwq0 0ms0kbC++202.7kb2023-12-10 20:05:122023-12-10 20:05:12

Judging History

This is the latest submission verdict.

  • [2023-12-10 20:05:12]
  • Judged
  • Verdict: 0
  • Time: 0ms
  • Memory: 0kb
  • [2023-12-10 20:05:12]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
namespace FastIO {
	#define iL (1 << 20)
	char ibuf[iL],*iS = ibuf + iL,*iT = ibuf + iL;
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread(ibuf,1,iL,stdin),iS == iT ? EOF : *iS++) : *iS++)
	template<typename T>
	inline void read(T &a)
	{
		char ch;int sign = 0;
		for(ch = gc();!isdigit(ch);ch = gc())
			if(ch == '-') sign = 1;
		a = ch & 15;
		for(ch = gc();isdigit(ch);ch = gc())
			a = (a << 3) + (a << 1) + (ch & 15);
		if(sign) a = -a;
	}
	char Out[iL],*iter = Out;
	#define flush() fwrite(Out,1,iter - Out,stdout),iter = Out
	template<typename T>
	inline void write(T x,char end = '\n')
	{
		int c[40],l = 0;if(x < 0) *iter++ = '-',x = -x;
		do c[++l] = x % 10,x /= 10; while(x);
		while(l) *iter++ = c[l--] + '0';
		flush();
	}
	#undef iL 
	#undef gc
	#undef flush
}
using namespace FastIO;
const int N = 1e6 + 5,M = 2.5e7 + 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) {
	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;
vector<int> Res;
inline void work() {
	read(n);
	for(int i = 1;i <= n;i++) read(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;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;
	}
	rts.clear();
	for(int i = 1;i <= n;i++) vis[i] = dif[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();Res.resize(n + 1);
	for(int S = 0;S < (1 << rts.size());++S) {
		for(int i = 0;i < rts.size();i++) co[rts[i]] = (S >> i) & 1;
		for(int i = 1;i <= n;i++) Res[i] = co[bel[i]] ^ dif[i];
		Ans.push_back(Res);
	}
	sort(Ans.begin(),Ans.end());
	printf("%d\n",(int)Ans.size());
	cerr << Ans.size() << endl;
	for(auto it : Ans)
		for(int i = 1;i <= n;i++)
			putchar(it[i] + 48),i == n ? (void)putchar('\n') : void();
	// cerr << 1.0 * clock() / CLOCKS_PER_SEC << endl;

}
int main() {
	// freopen("tmp.in","r",stdin);
	// freopen("tmp.out","w",stdout);
	int T;
	read(T);
	while(T--) work();
	// cerr << 1.0 * clock() / CLOCKS_PER_SEC << endl;
	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: