QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#664004 | #3223. Cellular Automaton | hansiyuan | WA | 0ms | 3848kb | C++14 | 1.4kb | 2024-10-21 18:54:29 | 2024-10-21 18:54:31 |
Judging History
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++){
int j = (i<<1)&(n-1);
if(j<=p){
if(a[j])
add(i,j,1) , add(j,i,-1);
else
add(i,j,0) , add(j,i,0);
}
else{
add(i,j,1) , add(j,i,0);
}
j++;
if(j<=p){
if(a[j])
add(i,j,0) , add(j,i,0);
else
add(i,j,-1) , add(j,i,1);
}
else{
add(i,j,0) , add(j,i,1);
}
}
for(int i=0;i<n;i++)
add(n,i,0);
memset(dis,0x3f,sizeof(dis));
memset(cnt,0,sizeof(cnt));
dis[n] = 0;
q.push(n);
vis[n] = 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+3)
return false;
}
}
}
}
return true;
}
int main(){
scanf("%d",&w);
n = 1<<(w*2+1);
for(int i=0;i<n;i++){
scanf("%1d",&b[i]);
}
for(int i=0;i<n;i++){
a[i] = b[i];
while(a[i]<=1 && !chk(i))
a[i]++;
if(a[i]>1) {puts("no"); return 0;}
printf("%d",a[i]);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3792kb
input:
1 11111111
output:
no
result:
ok single line: 'no'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3692kb
input:
1 11111101
output:
no
result:
ok single line: 'no'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3740kb
input:
1 11001011
output:
no
result:
ok single line: 'no'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3660kb
input:
1 10111110
output:
no
result:
ok single line: 'no'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3692kb
input:
1 10000010
output:
no
result:
ok single line: 'no'
Test #6:
score: -100
Wrong Answer
time: 0ms
memory: 3848kb
input:
1 00100011
output:
0010no
result:
wrong answer 1st lines differ - expected: '00110011', found: '0010no'