結果

問題 No.451 575
ユーザー pekempeypekempey
提出日時 2016-12-02 00:48:25
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 158 ms / 2,000 ms
コード長 1,094 bytes
コンパイル時間 1,680 ms
コンパイル使用メモリ 168,400 KB
実行使用メモリ 4,952 KB
最終ジャッジ日時 2023-08-22 12:43:18
合計ジャッジ時間 5,135 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 4 ms
4,380 KB
testcase_07 AC 21 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 40 ms
4,380 KB
testcase_11 AC 121 ms
4,836 KB
testcase_12 AC 157 ms
4,932 KB
testcase_13 AC 157 ms
4,888 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 5 ms
4,380 KB
testcase_17 AC 22 ms
4,376 KB
testcase_18 AC 22 ms
4,380 KB
testcase_19 AC 14 ms
4,376 KB
testcase_20 AC 7 ms
4,380 KB
testcase_21 AC 3 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 158 ms
4,952 KB
testcase_24 AC 91 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 3 ms
4,376 KB
testcase_30 AC 21 ms
4,376 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 7 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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