結果

問題 No.451 575
ユーザー tottoripapertottoripaper
提出日時 2016-12-31 23:18:55
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 154 ms / 2,000 ms
コード長 1,763 bytes
コンパイル時間 2,091 ms
コンパイル使用メモリ 145,332 KB
実行使用メモリ 4,988 KB
最終ジャッジ日時 2023-08-22 14:37:47
合計ジャッジ時間 5,558 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 4 ms
4,376 KB
testcase_07 AC 20 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 39 ms
4,376 KB
testcase_11 AC 119 ms
4,876 KB
testcase_12 AC 151 ms
4,988 KB
testcase_13 AC 154 ms
4,916 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 4 ms
4,376 KB
testcase_17 AC 21 ms
4,532 KB
testcase_18 AC 20 ms
4,544 KB
testcase_19 AC 14 ms
4,380 KB
testcase_20 AC 7 ms
4,376 KB
testcase_21 AC 3 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 150 ms
4,932 KB
testcase_24 AC 87 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 3 ms
4,380 KB
testcase_30 AC 21 ms
4,636 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 6 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)

using ll = long long;
using P = std::tuple<int,int>;

const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};

int N;
ll A[100100], B[100100];

bool isValid(){
    for(int i=0;i<N;i+=2){
        if(A[i] <= A[i+1]){return false;}
    }
    return true;
}

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    std::cin >> N;

    for(int i=0;i<N;++i){
        std::cin >> A[i];
    }

    if(N == 1){
        if(A[0] > 1){
            std::cout << 2 << std::endl;
            std::cout << 1 << std::endl;
            std::cout << (A[0] - 1) << std::endl;
        }else{
            std::cout << "-1" << std::endl;
        }
        return 0;
    }
    
    if(!isValid()){
        std::cout << "-1" << std::endl;
        return 0;
    }

    int M = (N + 1) / 2;
    for(int i=0;i<M;++i){
        B[i] = A[i*2] - A[i*2+1];
    }

    ll l = 0, u = B[M-1]; // (l, u)
    for(int i=M-1;i>0;--i){
        // std::cout << l << ", " << u << std::endl;
        l = std::min(l, B[i-1]);
        u = std::min(u, B[i-1]);
        ll nu = B[i-1] - l,
           nl = B[i-1] - u;
        if(std::abs(nl - nu) <= 1){
            // std::cout << "?: " << i << std::endl;
            std::cout << "-1" << std::endl;
            return 0;
        }
        l = nl; u = nu;
    }
    
    std::cout << (N+1) << std::endl;
    
    B[0] = l + 1;
    for(int i=0;i<N+1;++i){
        std::cout << B[i] << std::endl;

        if(i % 2 == 0){ // b_i = a_i + a_{i+1}
            B[i+1] = A[i] - B[i];
        }else{ // b_i = a_i - a_{i+1}
            B[i+1] = B[i] - A[i];
        }
    }
}
0