QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#424738 | #3223. Cellular Automaton | DaiRuiChen007 | Compile Error | / | / | C++14 | 1.2kb | 2024-05-29 16:28:40 | 2024-05-29 16:28:40 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
struct Edge { int v,w; };
vector <Edge> G[1<<10];
int n,m,k,dis[1<<10];
bool inq[1<<10],q[1<<11],p[1<<11];
bool spfa() {
memset(dis,0x3f,sizeof(dis));
memset(inq,0,sizeof(inq));
dis[0]=0,inq[0]=1;
queue <int> Q; Q.push(0);
while(Q.size()) {
int u=Q.front(); Q.pop(),inq[u]=false;
for(auto e:G[u]) if(dis[e.v]>dis[u]+e.w) {
dis[e.v]=dis[u]+e.w;
if(dis[0]<0) return false;
if(!inq[e.v]) inq[e.v]=true,Q.push(e.v);
}
}
return dis[0]>=0;
}
bool check(int i) {
for(int s=0;s<n;++s) G[s].clear();
for(int s=0;s<n;++s) {
int t=(s<<1)&(n-1);
for(int c:{0,1}) {
int l,r,z=s<<1|c;
if(z<=i) l=r=p[z]-c;
else l=-c,r=1-c;
G[s].push_back({t|c,r});
G[t|c].push_back({s,-l});
}
}
return spfa();
}
signed main() {
scanf("%d",&k),n=1<<(2*k),m=2*n;
for(int i=0;i<m;++i) scanf("%1d",&q[i]),p[i]=q[i];
if(check(m-1)) {
for(int i=0;i<m;++i) printf("%d",q[i]);
puts(""); return ;
}
for(int i=m-1;~i;--i) if(q[i]==0) {
for(int j=0;j<i;++j) p[j]=q[j];
p[i]=1;
for(int j=i+1;j<m;++j) p[j]=0;
if(!check(i)) continue;
for(int j=i+1;j<m;++j) if(!check(j)) p[j]=1;
for(int j=0;j<m;++j) printf("%d",p[j]);
puts(""); return 0;
}
puts("-1");
}
Details
answer.code: In function ‘int main()’: answer.code:38:39: warning: format ‘%d’ expects argument of type ‘int*’, but argument 2 has type ‘bool*’ [-Wformat=] 38 | for(int i=0;i<m;++i) scanf("%1d",&q[i]),p[i]=q[i]; | ~~^ ~~~~~ | | | | | bool* | int* answer.code:41:27: error: return-statement with no value, in function returning ‘int’ [-fpermissive] 41 | puts(""); return ; | ^~~~~~ answer.code:37:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 37 | scanf("%d",&k),n=1<<(2*k),m=2*n; | ~~~~~^~~~~~~~~ answer.code:38:35: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 38 | for(int i=0;i<m;++i) scanf("%1d",&q[i]),p[i]=q[i]; | ~~~~~^~~~~~~~~~~~~