結果

問題 No.451 575
ユーザー KKT89KKT89
提出日時 2020-07-13 17:59:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 1,307 bytes
コンパイル時間 1,196 ms
コンパイル使用メモリ 112,168 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-25 10:35:49
合計ジャッジ時間 4,383 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 4 ms
5,376 KB
testcase_07 AC 22 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 10 ms
5,376 KB
testcase_11 AC 28 ms
5,376 KB
testcase_12 AC 37 ms
5,376 KB
testcase_13 AC 36 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 5 ms
5,376 KB
testcase_17 AC 23 ms
5,376 KB
testcase_18 AC 22 ms
5,376 KB
testcase_19 AC 15 ms
5,376 KB
testcase_20 AC 3 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 38 ms
5,376 KB
testcase_24 AC 18 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 1 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 4 ms
5,376 KB
testcase_30 AC 24 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 7 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
using namespace std;
typedef long long int ll;
using ull = unsigned long long;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n; cin >> n;
    vector<ll> b(n);
    for(int i=0;i<n;i++){
        cin >> b[i];
    }
    ll l=1LL,r=1LL<<60;
    for(int i=0;i<n;i++){
        ll nl,nr;
        if(i%2==0){
            nl=max(1LL,b[i]-r);
            nr=b[i]-l;
        }
        else{
            nl=max(1LL,l-b[i]);
            nr=r-b[i];
        }
        l=nl,r=nr;
    }
    if(l>r){
        printf("-1\n");
    }
    else{
        vector<ll> a(n+1);
        a[n]=l;
        bool ok=1;
        for(int i=n-1;i>=0;i--){
            if(i%2){
                a[i]=b[i]+a[i+1];
            }
            else{
                a[i]=b[i]-a[i+1];
            }
            if(a[i]<0)ok=0;
        }
        if(!ok){
            printf("-1\n");
            return 0;
        }
        printf("%d\n",n+1);
        for(int i=0;i<=n;i++){
            printf("%lld\n",a[i]);
        }
    }
}
0