結果

問題 No.451 575
ユーザー mamekin
提出日時 2016-12-11 19:31:24
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 204 ms / 2,000 ms
コード長 1,459 bytes
コンパイル時間 1,204 ms
コンパイル使用メモリ 103,796 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-12-17 12:45:07
合計ジャッジ時間 5,255 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

const long long MIN = 1LL;
const long long MAX = 1000000000000000000LL;

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

    long long aMin = MIN;
    long long aMax = MAX;
    bool sign = true;
    long long x = 0;
    for(int i=0; i<n; ++i){
        if(i % 2 == 0){
            sign = !sign;
            x *= -1;
            x += b[i];
        }
        else{
            x -= b[i];
        }

        if(sign){
            aMin = max(aMin, MIN - x);
            aMax = min(aMax, MAX - x);
        }
        else{
            aMin = max(aMin, x - MAX);
            aMax = min(aMax, x - MIN);
        }

        if(aMax < aMin){
            cout << -1 << endl;
            return 0;
        }
    }

    cout << (n + 1) << endl;
    long long a = aMin;
    cout << a << endl;
    for(int i=0; i<n; ++i){
        if(i % 2 == 0)
            a = b[i] - a;
        else
            a = a - b[i];
        cout << a << endl;
    }

    return 0;
}
0