結果
| 問題 |
No.451 575
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-08-04 15:01:10 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 154 ms / 2,000 ms |
| コード長 | 1,801 bytes |
| コンパイル時間 | 1,618 ms |
| コンパイル使用メモリ | 171,492 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-11 20:50:10 |
| 合計ジャッジ時間 | 5,765 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 29 |
ソースコード
// {{{ Templates
#include <bits/stdc++.h>
#define show(x) cerr << #x << " = " << x << endl
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
os << "sz:" << v.size() << "\n[";
for (const auto& p : v) {
os << p << ",";
}
os << "]\n";
return os;
}
template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
os << "(" << p.first << "," << p.second
<< ")";
return os;
}
constexpr ll MOD = (ll)1e9 + 7LL;
template <typename T>
constexpr T INF = numeric_limits<T>::max() / 100;
// }}}
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<ll> b(n);
for (int i = 0; i < n; i++) {
cin >> b[i];
}
vector<bool> plus(n + 1);
for (int i = 0; i <= n; i++) {
plus[i] = (i % 4 == 0 or i % 4 == 3);
}
vector<ll> offset(n + 1);
offset[0] = 0;
for (int i = 1; i <= n; i++) {
offset[i] = (i % 2 == 0) ? offset[i - 1] : -offset[i - 1];
offset[i] += (i % 2 == 0) ? -b[i - 1] : b[i - 1];
}
constexpr ll MAX = (ll)1e18;
ll lower = 1;
ll upper = MAX;
for (int i = 0; i <= n; i++) {
if (plus[i]) {
lower = max(lower, 1 - offset[i]);
upper = min(upper, MAX - offset[i]);
} else {
lower = max(lower, offset[i] - MAX);
upper = min(upper, offset[i] - 1);
}
}
if (lower > upper) {
cout << -1 << endl;
} else {
cout << n + 1 << endl;
const ll a0 = lower;
for (int i = 0; i <= n; i++) {
cout << offset[i] + (plus[i] ? a0 : -a0) << endl;
}
}
return 0;
}