結果

問題 No.451 575
ユーザー KKT89
提出日時 2020-07-13 17:59:00
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 1,307 bytes
コンパイル時間 1,355 ms
コンパイル使用メモリ 108,604 KB
最終ジャッジ日時 2025-01-11 20:17:42
ジャッジサーバーID
(参考情報)
judge4 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

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