結果

問題 No.451 575
ユーザー imulanimulan
提出日時 2016-12-02 04:29:20
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 1,415 bytes
コンパイル時間 1,566 ms
コンパイル使用メモリ 172,500 KB
実行使用メモリ 6,520 KB
最終ジャッジ日時 2023-08-22 13:25:31
合計ジャッジ時間 4,440 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 4 ms
4,376 KB
testcase_07 AC 22 ms
5,428 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 10 ms
4,376 KB
testcase_11 AC 27 ms
5,972 KB
testcase_12 AC 35 ms
6,464 KB
testcase_13 AC 35 ms
6,520 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 5 ms
4,380 KB
testcase_17 AC 22 ms
5,428 KB
testcase_18 AC 22 ms
5,532 KB
testcase_19 AC 15 ms
4,560 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 35 ms
6,488 KB
testcase_24 AC 17 ms
4,988 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 4 ms
4,380 KB
testcase_30 AC 22 ms
5,472 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 7 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

typedef pair<ll,int> P;

const ll LIM=1000000000000000000LL;

vector<ll> solve(int n, vector<ll> &b)
{
    vector<ll> fail(1,-1);

    vector<P> a(n+2);
    a[1]=P(0LL,1);
    for(int i=2; i<=n+1; ++i)
    {
        ll val=a[i-1].fi-b[i-1];
        int x=a[i-1].se;
        if(i%2==0)
        {
            val*=-1;
            x*=-1;
            if(abs(val)>LIM*2) return fail;
        }
        a[i]=P(val,x);
    }

    // a[1]の値としてありうる範囲を調べる
    ll l=1, r=LIM;
    for(int i=2; i<=n+1; ++i)
    {
        if(a[i].se==-1)
        {
            l=max(l,a[i].fi-LIM);
            r=min(r,a[i].fi-1);
        }
        else
        {
            l=max(l,1-a[i].fi);
            r=min(r,LIM-a[i].fi);
        }
    }

    if(l>r) return fail;

    // 構成
    vector<ll> ret;
    ret.pb(n+1);
    ret.pb(l);
    for(int i=2; i<=n+1; ++i) ret.pb(a[i].fi + a[i].se*l);

    return ret;
}

int main()
{
    int n;
    scanf(" %d", &n);
    vector<ll> b(n+1);
    rep(i,n) scanf(" %lld", &b[i+1]);

    vector<ll> ans=solve(n,b);
    rep(i,ans.size()) printf("%lld\n", ans[i]);
    return 0;
}
0