結果
問題 | No.451 575 |
ユーザー |
|
提出日時 | 2016-12-02 00:48:25 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 155 ms / 2,000 ms |
コード長 | 1,094 bytes |
コンパイル時間 | 1,592 ms |
コンパイル使用メモリ | 170,448 KB |
実行使用メモリ | 5,468 KB |
最終ジャッジ日時 | 2024-12-16 09:46:35 |
合計ジャッジ時間 | 4,627 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 29 |
ソースコード
#include <bits/stdc++.h> using namespace std; const int64_t X = 1e18; int main() { int n; cin >> n; vector<int64_t> b(n); for (int i = 0; i < n; i++) { scanf("%lld", &b[i]); if ((i + 1) / 2 % 2 == 1) { b[i] *= -1; } } for (int i = 1; i < n; i++) { b[i] += b[i - 1]; if (abs(b[i]) > 2e18) { cout << -1 << endl; return 0; } } int64_t L = 1; int64_t R = X; for (int i = 0; i < n; i++) { if (i / 2 % 2 == 0) { L = max(L, -X + b[i]); R = min(R, -1 + b[i]); } else { L = max(L, 1 + b[i]); R = min(R, X + b[i]); } } if (L > R) { cout << -1 << endl; return 0; } vector<int64_t> a; a.push_back(L); for (int i = 0; i < n; i++) { if (i / 2 % 2 == 0) { a.push_back(-L + b[i]); } else { a.push_back(L - b[i]); } } cout << a.size() << endl; for (int i = 0; i <= n; i++) { cout << a[i] << endl; } }