提交时间:2023-10-05 07:59:51

运行 ID: 105018

#include<bits/stdc++.h> using namespace std; #define int long long int b[10100],a[10100],n,ff,c[10100]; signed main() { cin>>n; for(int i=1;i<=n;++i) cin>>a[i]; if(a[1]==2) b[1]=b[2]=1; if(a[1]==1) b[1]=1; for(int i=2;i<=n;++i) { if(a[i-1]-b[i-1]-b[i-2]<0 || a[i-1]-b[i-1]-b[i-2]>1) { ff=1; break; } b[i]=a[i-1]-b[i-1]-b[i-2]; } for(int i=1;i<=n;++i) c[i]=b[i-1]+b[i]+b[i+1], ff+=c[i]==a[i]?1:0; if(ff!=n) { ff=0, memset(b,0,sizeof(b)); if(a[1]==1) b[2]=1; if(a[1]==2) b[1]=b[2]=1; for(int i=2;i<=n;++i) { if(a[i-1]-b[i-1]-b[i-2]<0 || a[i-1]-b[i-1]-b[i-2]>1) { ff=1; break; } b[i]=a[i-1]-b[i-1]-b[i-2]; } } ff=0; for(int i=1;i<=n;++i) c[i]=b[i-1]+b[i]+b[i+1], ff+=c[i]==a[i]?1:0; if(ff!=n) return cout<<"No answer", 0; if(n==1 && a[1]>1) return cout<<"No answer", 0; for(int i=1;i<=n;++i) cout<<b[i]<<" "; return 0; }