QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#599697 | #3223. Cellular Automaton | dongyc666 | WA | 1ms | 4120kb | C++14 | 1.5kb | 2024-09-29 09:12:52 | 2024-09-29 09:12:53 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int NR=3000;
int n,dis[NR],vis[NR],st[NR*15],L,R;
char str[NR],ans[NR];
#define pii pair<int,int>
#define fi first
#define se second
#define mkp make_pair
#define pb emplace_back
vector<pii>g[NR];
bool SPFA(){
memset(dis,999999,sizeof(dis));
memset(vis,0,sizeof(vis));
L=R=1;st[1]=0;dis[0]=0;
while(L<=R){
int x=st[L];L++;
if(vis[x]>4*n)return 0;
vis[x]++;
// printf("x:%d %d\n",x,dis[x]);
for(auto lcy:g[x])
if(dis[lcy.fi]>dis[x]+lcy.se){
dis[lcy.fi]=dis[x]+lcy.se;
st[++R]=lcy.fi;
}
}
return 1;
}
bool check(int k){
for(int i=0;i<(1<<(2*n));i++)g[i].clear();
// printf("check:%d %s\n",k,ans);
for(int s=0;s<(1<<(2*n+1));s++){
int x=s>>1,y=s&((1<<(2*n))-1);
if(s<=k){
int val=(ans[s]-'0')-(s&1);
g[x].pb(mkp(y,val));g[y].pb(mkp(x,-val));
}
else{
if(s&1)g[x].pb(mkp(y,0)),g[y].pb(mkp(x,1));
else g[x].pb(mkp(y,1)),g[y].pb(mkp(x,0));
}
}
if(SPFA())return 1;
return 0;
}
bool Check(int x){
ans[x]='0';
return check(x);
}
int main(){
cin>>n;
scanf("%s",str);
if(!check(-1)){
puts("no");
return 0;
}
bool ok=0;
for(int i=0;i<(1<<(2*n+1));i++){
if(ok){
if(Check(i))ans[i]='0';
else ans[i]='1';
}
else{
if(str[i]=='1'){
ans[i]='1';
if(!check(i)){
puts("no");
return 0;
}
}
else{
int j=i+1;
for(;str[j]=='1';j++)ans[j]='1';
ans[i]='0';
if(check(j-1))ans[i]='0';
else ans[i]='1',ok=1;
}
}
}
printf("%s\n",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3760kb
input:
1 11111111
output:
no
result:
ok single line: 'no'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3776kb
input:
1 11111101
output:
no
result:
ok single line: 'no'
Test #3:
score: 0
Accepted
time: 0ms
memory: 4028kb
input:
1 11001011
output:
no
result:
ok single line: 'no'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3760kb
input:
1 10111110
output:
no
result:
ok single line: 'no'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3776kb
input:
1 10000010
output:
no
result:
ok single line: 'no'
Test #6:
score: 0
Accepted
time: 0ms
memory: 4120kb
input:
1 00100011
output:
00110011
result:
ok single line: '00110011'
Test #7:
score: 0
Accepted
time: 0ms
memory: 4116kb
input:
1 01000001
output:
01000111
result:
ok single line: '01000111'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3820kb
input:
1 00000100
output:
00001111
result:
ok single line: '00001111'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3884kb
input:
1 01001000
output:
01010101
result:
ok single line: '01010101'
Test #10:
score: 0
Accepted
time: 0ms
memory: 4056kb
input:
1 00001000
output:
00001111
result:
ok single line: '00001111'
Test #11:
score: 0
Accepted
time: 0ms
memory: 4088kb
input:
1 00000000
output:
00001111
result:
ok single line: '00001111'
Test #12:
score: 0
Accepted
time: 0ms
memory: 3824kb
input:
2 11111111111111111111111111111111
output:
no
result:
ok single line: 'no'
Test #13:
score: 0
Accepted
time: 0ms
memory: 3760kb
input:
2 11111111001111111111111111111110
output:
no
result:
ok single line: 'no'
Test #14:
score: 0
Accepted
time: 0ms
memory: 3756kb
input:
2 11111011011111001110111011011101
output:
no
result:
ok single line: 'no'
Test #15:
score: 0
Accepted
time: 0ms
memory: 3696kb
input:
2 11011101110111101111111101110111
output:
no
result:
ok single line: 'no'
Test #16:
score: 0
Accepted
time: 0ms
memory: 3828kb
input:
2 11011011111000101011001101110011
output:
no
result:
ok single line: 'no'
Test #17:
score: 0
Accepted
time: 0ms
memory: 3896kb
input:
2 00010000010001100111101111101110
output:
00010000010100001101111101011111
result:
ok single line: '00010000010100001101111101011111'
Test #18:
score: 0
Accepted
time: 0ms
memory: 3824kb
input:
2 01001010101010011010011000111001
output:
01010000010100000101111101011111
result:
ok single line: '01010000010100000101111101011111'
Test #19:
score: 0
Accepted
time: 0ms
memory: 3700kb
input:
2 10001110000000000000010000100001
output:
no
result:
ok single line: 'no'
Test #20:
score: -100
Wrong Answer
time: 1ms
memory: 3884kb
input:
2 00100010010010010000001000000101
output:
00100010111111111111111111111111
result:
wrong answer 1st lines differ - expected: '00100011000000000010111111111111', found: '00100010111111111111111111111111'