結果

問題 No.451 575
ユーザー hanorverhanorver
提出日時 2016-12-02 10:14:02
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 452 ms / 2,000 ms
コード長 1,004 bytes
コンパイル時間 707 ms
コンパイル使用メモリ 69,888 KB
実行使用メモリ 4,740 KB
最終ジャッジ日時 2023-08-22 13:27:15
合計ジャッジ時間 5,116 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 10 ms
4,376 KB
testcase_07 AC 65 ms
4,564 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 50 ms
4,376 KB
testcase_11 AC 150 ms
4,380 KB
testcase_12 AC 192 ms
4,636 KB
testcase_13 AC 199 ms
4,604 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 4 ms
4,376 KB
testcase_16 AC 98 ms
4,376 KB
testcase_17 AC 182 ms
4,668 KB
testcase_18 AC 66 ms
4,556 KB
testcase_19 AC 47 ms
4,376 KB
testcase_20 AC 9 ms
4,380 KB
testcase_21 AC 3 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 195 ms
4,740 KB
testcase_24 AC 101 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 13 ms
4,376 KB
testcase_29 AC 22 ms
4,376 KB
testcase_30 AC 452 ms
4,608 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 15 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

int main() {
    long long n;
    std::cin >> n;

    std::vector<long long> b(n);
    for (int i = 0; i < n; i++) {
        std::cin >> b[i];
    }

    if (b[0] == 1) {
        std::cout << -1 << std::endl;
        return 0;
    }

    int miss_count = 0;
    std::vector<long long> a(n + 1, 0);
    a[0] = 1;
    for (int i = 0; i < n; i++) {
        if (i % 2 == 0) {
            a[i + 1] = b[i] - a[i];
        } else {
            a[i + 1] = a[i] - b[i];
        }
        if (a[i + 1] <= 0 || a[i + 1] > 1000000000000000000) {
            a[0] += -a[i + 1] + 1;
            i = -1;
            miss_count++;
        }
        if (miss_count == 10000) {
            std::cout << -1 << std::endl;
            return 0;
        }
    }

    if (a[0] <= 0) {
        std::cout << -1 << std::endl;
        return 0;
    }

    std::cout << a.size() << std::endl;
    for (int i = 0; i < n + 1; i++) {
        std::cout << a[i] << std::endl;
    }

    return 0;
}
0