結果

問題 No.451 575
ユーザー beetbeet
提出日時 2018-11-07 17:24:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 194 ms / 2,000 ms
コード長 1,134 bytes
コンパイル時間 2,243 ms
コンパイル使用メモリ 205,836 KB
実行使用メモリ 6,528 KB
最終ジャッジ日時 2024-04-30 22:30:52
合計ジャッジ時間 6,662 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 9 ms
5,376 KB
testcase_07 AC 62 ms
5,632 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 48 ms
5,376 KB
testcase_11 AC 159 ms
5,632 KB
testcase_12 AC 189 ms
6,528 KB
testcase_13 AC 188 ms
6,400 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 4 ms
5,376 KB
testcase_16 AC 11 ms
5,376 KB
testcase_17 AC 60 ms
5,504 KB
testcase_18 AC 63 ms
5,632 KB
testcase_19 AC 43 ms
5,376 KB
testcase_20 AC 10 ms
5,376 KB
testcase_21 AC 4 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 194 ms
6,528 KB
testcase_24 AC 93 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 1 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 7 ms
5,376 KB
testcase_30 AC 62 ms
5,632 KB
testcase_31 AC 1 ms
5,376 KB
testcase_32 AC 16 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0