85分代码,不会改了。挂出来求救
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #include<string> using namespace std; inline int read(){ int ans=0; char last=' ',ch=getchar(); while(ch>'9'||ch<'0') last=ch,ch=getchar(); while(ch<='9'&&ch>='0') ans=(ans<<1)+(ans<<3)+ch-'0',ch=getchar(); if(last=='-') ans=-ans; return ans; } int n,cnt; int a[10005],b[10005]; bool ans[10005],d[10005];//da an xu lie int main(){ freopen("bomp.in","r",stdin); freopen("bomp.out","w",stdout); n=read(); for(int i=1;i<=n;i++){ a[i]=read(); if((i!=1&&abs(a[i]-a[i-1])>1)||a[i]>3){ printf("No answer"); return 0; } if(a[i]==3) { ans[i]=ans[i-1]=ans[i+1]=1; d[i]=d[i-1]=d[i+1]=1;//biao ji yi jing bu neng xiu gai le b[++cnt]=i; } } if(a[1]==3||a[n]==3){printf("No answer");return 0;}//one specil judge; int lnow,rnow,now=1,k,cn=0; for(int i=1;i<=cnt;i++){ lnow=b[i]-1;rnow=b[i]+1;k=b[i]; while(lnow>=now){ int cc=0; lnow--;rnow--;k--; if(ans[lnow]==1) cc++; if(ans[lnow+1]==1) cc++; if(ans[rnow]==1) cc++; if(cc==a[k]) { d[rnow]=d[lnow+1]=d[lnow]=1; continue; } else { if(cc>a[k]){ printf("No answer"); return 0; } else { int c=a[k]-cc; if(!d[lnow]&&ans[lnow]==0&&c!=0&&i!=1) ans[lnow]=1,c--; if(!d[lnow+1]&&ans[lnow+1]==0&&c!=0) ans[lnow+1]=1,c--; if(!d[rnow]&&ans[rnow]==0&&c!=0&&i!=n) ans[rnow]=1,c--; if(c!=0){ printf("%d",i); printf("No answer"); return 0; } } } d[lnow]=d[lnow+1]=d[rnow]=1; } now=a[i]+1; } for(int i=b[cnt]+1;i<=n;i++){//mei ju xia fang shen xian cao zuo lnow=i-1;rnow=i+1;int cc=0; if(ans[lnow]==1) cc++; if(ans[lnow+1]==1) cc++; if(ans[rnow]==1) cc++; if(cc==a[i]) { d[lnow]=d[lnow+1]=d[rnow]=1; continue; } else { if(cc>a[i]){ printf("No answer"); return 0; } else { int c=a[i]-cc; if(!d[rnow]&&ans[rnow]==0&&c!=0&&i!=n) ans[rnow]=1,c--; if(!d[lnow+1]&&ans[lnow+1]==0&&c!=0) ans[lnow+1]=1,c--; if(!d[lnow]&&ans[lnow]==0&&c!=0&&i!=1) ans[lnow]=1,c--; if(c!=0){ printf("No answer"); return 0; } } } d[lnow]=d[lnow+1]=d[rnow]=1; } for(int i=1;i<=n;i++) printf("%d ",ans[i]); return 0; }
qwqwqwqwqwq