提交时间:2023-10-04 11:06:49
运行 ID: 104918
#include<bits/stdc++.h> using namespace std; #define int unsigned long long int b[10100],a[10100],n,ff; 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]; } if(ff) { ff=0, memset(a,0,sizeof(a)), 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]; } } if(ff) return cout<<"No answer", 0; for(int i=1;i<=n;++i) cout<<b[i]<<" "; return 0; }