結果

問題 No.451 575
ユーザー parukiparuki
提出日時 2016-12-02 00:41:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 170 ms / 2,000 ms
コード長 1,766 bytes
コンパイル時間 1,663 ms
コンパイル使用メモリ 168,484 KB
実行使用メモリ 4,724 KB
最終ジャッジ日時 2023-08-22 12:39:25
合計ジャッジ時間 5,439 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 4 ms
4,376 KB
testcase_07 AC 21 ms
4,532 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 43 ms
4,376 KB
testcase_11 AC 127 ms
4,436 KB
testcase_12 AC 170 ms
4,608 KB
testcase_13 AC 169 ms
4,696 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 8 ms
4,376 KB
testcase_17 AC 36 ms
4,672 KB
testcase_18 AC 21 ms
4,724 KB
testcase_19 AC 24 ms
4,376 KB
testcase_20 AC 8 ms
4,380 KB
testcase_21 AC 3 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 168 ms
4,548 KB
testcase_24 AC 95 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 5 ms
4,380 KB
testcase_30 AC 36 ms
4,696 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 7 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

ll MA = (ll)1e18;
ll a[100001];
int f(vll &b, ll x) {
    int res = 0;
    a[0] = x;
    for(int i = 1; i <= sz(b); ++i) {
        if(i & 1) {
            x = b[i - 1] - a[i - 1];
        } else {
            x = a[i - 1] - b[i - 1];
        }
        int k = (i - 1) / 2;
        if(k & 1) {
            if(x > MA)res |= 1;
            if(x < 1)res |= 2;
        } else {
            if(x < 1)res |= 1;
            if(x > MA)res |= 2;
        }
        a[i] = x;
    }
    return res;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    while(cin >> n) {
        vll b(n);
        rep(i, n)cin >> b[i];
        if((f(b, 1) & 1) || (f(b, MA) & 2)) {
            cout << -1 << endl;
            continue;
        }

        ll lb = 1, ub = MA, m;
        // [l,R]
        ll L = 1, R = MA;
        if(f(b, MA) & 1) {
            // [lb, ub)
            while(ub - lb > 1) {
                m = (ub + lb) / 2;
                ((f(b, m) & 1) ? ub : lb) = m;
            }
            R = lb;
        }

        if(f(b, R) & 2) {
            cout << -1 << endl;
        } else {
            cout << n + 1 << endl;
            rep(i, n + 1) {
                cout << a[i] << endl;
            }
        }
    }
}
0