結果
問題 | No.451 575 |
ユーザー |
![]() |
提出日時 | 2016-12-04 12:21:25 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 145 ms / 2,000 ms |
コード長 | 799 bytes |
コンパイル時間 | 1,775 ms |
コンパイル使用メモリ | 171,500 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-12-17 12:33:29 |
合計ジャッジ時間 | 6,079 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 29 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll MAX = 1e18; ll b[100010]; int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; for(int i = 0; i < n; i++) { cin >> b[i]; } ll l = 1, r = MAX; for(int i = 0; i < n; i++) { ll nl, nr; // add if(i % 2 == 0) { nl = max(b[i] - r, 1LL); nr = b[i] - l; } // sub else { nl = max(l - b[i], 1LL); nr = r - b[i]; } l = nl, r = nr; if(l > r) { cout << -1 << endl; return 0; } } cout << n + 1 << endl; vector<ll> a; ll v = l; a.push_back(v); for(int i = n - 1; i >= 0; i--) { // add if(i % 2 == 0) { v = b[i] - v; } // sub else { v += b[i]; } a.push_back(v); } reverse(a.begin(), a.end()); for(auto aa : a) { cout << aa << endl; } }