結果

問題 No.451 575
ユーザー hanorverhanorver
提出日時 2016-12-02 10:14:02
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 443 ms / 2,000 ms
コード長 1,004 bytes
コンパイル時間 767 ms
コンパイル使用メモリ 70,652 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-16 10:49:32
合計ジャッジ時間 4,712 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

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