結果
問題 |
No.451 575
|
ユーザー |
![]() |
提出日時 | 2018-11-07 17:24:12 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 186 ms / 2,000 ms |
コード長 | 1,134 bytes |
コンパイル時間 | 1,770 ms |
コンパイル使用メモリ | 199,712 KB |
最終ジャッジ日時 | 2025-01-06 15:49:23 |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 29 |
ソースコード
#include<bits/stdc++.h> using namespace std; using Int = long long; template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;} //INSERT ABOVE HERE signed main(){ Int n; cin>>n; vector<Int> b(n); for(Int i=0;i<n;i++) cin>>b[i]; using P = pair<Int, Int>; auto sub=[&](P x,P y){ x.first-=y.first; x.second-=y.second; return x; }; vector<P> vp(n+1); vp[0]=P(1,0); for(Int i=0;i<n;i++){ if(~i&1) vp[i+1]=sub(P(0,b[i]),vp[i]); else vp[i+1]=sub(vp[i],P(0,b[i])); } const Int INF = 1e18; Int l=-INF*2,r=INF*2; for(Int i=0;i<=n;i++){ if(vp[i].first<0){ chmax(l,vp[i].second-INF); chmin(r,vp[i].second-1); }else{ chmax(l,-vp[i].second+1); chmin(r,-vp[i].second+INF); } } if(l>r){ cout<<-1<<endl; return 0; } vector<Int> a(n+1,l); for(Int i=0;i<n;i++){ if(~i&1) a[i+1]=b[i]-a[i]; else a[i+1]=a[i]-b[i]; } cout<<n+1<<endl; for(Int x:a) cout<<x<<endl; return 0; }