QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#664452#3223. Cellular AutomatonhansiyuanWA 210ms4088kbC++141.6kb2024-10-21 20:43:482024-10-21 20:43:48

Judging History

你现在查看的是最新测评结果

  • [2024-10-21 20:43:48]
  • 评测
  • 测评结果:WA
  • 用时:210ms
  • 内存:4088kb
  • [2024-10-21 20:43:48]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N=1e3;
int w,n;
int b[N];
int a[N];
int h[N],ne[N],to[N],we[N],idx;
void add(int a,int b,int c){
	// printf("%d--%d %d\n",a,b,c);
	to[++idx]=b; we[idx]=c; ne[idx]=h[a]; h[a]=idx;
}
int dis[N],cnt[N];
bool vis[N];
queue<int> q;
bool chk(int p){
	memset(h,0,sizeof(h)); idx=0;
	for(int i=0;i<n;i++){
		if(i<=p){
			add(i+n,i,(i&1)-a[i]);
			add(i,i+n,a[i]-(i&1));
		}
		else{
			if(i&1) add(i,i+n,0) , add(i+n,i,1);
			else add(i,i+n,1) , add(i+n,i,0);
		}
		add(i+n,(i<<1)&(n-1),0);
		add((i<<1)&(n-1),i+n,0);
		add(i+n,(i<<1)&(n-1)|1,0);
		add((i<<1)&(n-1)|1,i+n,0);
	}
	for(int i=0;i<n*2;i++)
		add(n*2,i,0);
	memset(dis,0x3f,sizeof(dis));
	memset(cnt,0,sizeof(cnt));
	memset(vis,0,sizeof(vis));
	while(q.size()) q.pop();
	dis[n*2] = 0;
	q.push(n*2);
	vis[n*2] = 1;
	while(q.size()){
		int u = q.front();
		q.pop();
		vis[u] = 0;
		for(int i=h[u];i;i=ne[i]){
			int v = to[i];
			if(dis[v] > dis[u]+we[i]){
				dis[v] = dis[u]+we[i];
				if(!vis[v]){
					q.push(v);
					vis[v] = 1;
					if(++cnt[v]>n*2+3)
						return false;
				}
			}
		}
	}
	return true;
}
void print(){
	for(int i=0;i<n;i++)
		printf("%d",a[i]);
}
int main(){
	scanf("%d",&w);
	n = 1<<(w*2+1);
	for(int i=0;i<n;i++){
		scanf("%1d",&b[i]);
		a[i] = b[i];
	}
	if(chk(n-1)) {print(); return 0;}
	for(int i=n-1;i>=0;i--){
		if(b[i]) continue;
		a[i] = 1;
		if(chk(i)){
			for(int j=i+1;j<n;j++){
				a[j] = 0;
				if(!chk(j)) a[j]=1;
			}
			print(); return 0;
		}
	}
	puts("no");
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3604kb

input:

1
11111111

output:

no

result:

ok single line: 'no'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3636kb

input:

1
11111101

output:

no

result:

ok single line: 'no'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3632kb

input:

1
11001011

output:

no

result:

ok single line: 'no'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3736kb

input:

1
10111110

output:

no

result:

ok single line: 'no'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3928kb

input:

1
10000010

output:

no

result:

ok single line: 'no'

Test #6:

score: 0
Accepted
time: 0ms
memory: 4088kb

input:

1
00100011

output:

00110011

result:

ok single line: '00110011'

Test #7:

score: 0
Accepted
time: 0ms
memory: 4052kb

input:

1
01000001

output:

01000111

result:

ok single line: '01000111'

Test #8:

score: 0
Accepted
time: 0ms
memory: 4088kb

input:

1
00000100

output:

00001111

result:

ok single line: '00001111'

Test #9:

score: 0
Accepted
time: 0ms
memory: 3824kb

input:

1
01001000

output:

01010101

result:

ok single line: '01010101'

Test #10:

score: 0
Accepted
time: 0ms
memory: 3828kb

input:

1
00001000

output:

00001111

result:

ok single line: '00001111'

Test #11:

score: 0
Accepted
time: 0ms
memory: 3824kb

input:

1
00000000

output:

00001111

result:

ok single line: '00001111'

Test #12:

score: 0
Accepted
time: 0ms
memory: 3960kb

input:

2
11111111111111111111111111111111

output:

no

result:

ok single line: 'no'

Test #13:

score: 0
Accepted
time: 0ms
memory: 3628kb

input:

2
11111111001111111111111111111110

output:

no

result:

ok single line: 'no'

Test #14:

score: 0
Accepted
time: 1ms
memory: 3680kb

input:

2
11111011011111001110111011011101

output:

no

result:

ok single line: 'no'

Test #15:

score: 0
Accepted
time: 1ms
memory: 3732kb

input:

2
11011101110111101111111101110111

output:

no

result:

ok single line: 'no'

Test #16:

score: 0
Accepted
time: 1ms
memory: 3632kb

input:

2
11011011111000101011001101110011

output:

no

result:

ok single line: 'no'

Test #17:

score: 0
Accepted
time: 1ms
memory: 3824kb

input:

2
00010000010001100111101111101110

output:

00010000010100001101111101011111

result:

ok single line: '00010000010100001101111101011111'

Test #18:

score: 0
Accepted
time: 1ms
memory: 3884kb

input:

2
01001010101010011010011000111001

output:

01010000010100000101111101011111

result:

ok single line: '01010000010100000101111101011111'

Test #19:

score: 0
Accepted
time: 1ms
memory: 3924kb

input:

2
10001110000000000000010000100001

output:

no

result:

ok single line: 'no'

Test #20:

score: 0
Accepted
time: 1ms
memory: 4036kb

input:

2
00100010010010010000001000000101

output:

00100011000000000010111111111111

result:

ok single line: '00100011000000000010111111111111'

Test #21:

score: 0
Accepted
time: 1ms
memory: 3828kb

input:

2
00100000000001000000100000000000

output:

00100000000011110010110011111111

result:

ok single line: '00100000000011110010110011111111'

Test #22:

score: 0
Accepted
time: 1ms
memory: 3808kb

input:

2
00000000000000000000000000000000

output:

00000000000000001111111111111111

result:

ok single line: '00000000000000001111111111111111'

Test #23:

score: 0
Accepted
time: 4ms
memory: 3672kb

input:

3
11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111

output:

no

result:

ok single line: 'no'

Test #24:

score: -100
Wrong Answer
time: 210ms
memory: 3756kb

input:

3
10101011111111111111111111111111110111111111110011111111111111101111111110111101111111111111111100111111101111101011111110111111

output:

10110000000000000000000000000000010101000100000001110000000000000101010101010111010101110011111101010111011111110111111111111111

result:

wrong answer 1st lines differ - expected: 'no', found: '101100000000000000000000000000...1010111011111110111111111111111'