結果

問題 No.451 575
ユーザー tottoripapertottoripaper
提出日時 2016-12-31 23:17:20
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,749 bytes
コンパイル時間 1,469 ms
コンパイル使用メモリ 159,064 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-09 19:19:59
合計ジャッジ時間 6,082 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 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 20 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 38 ms
5,376 KB
testcase_11 AC 117 ms
5,376 KB
testcase_12 AC 147 ms
5,376 KB
testcase_13 AC 149 ms
5,376 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 8 ms
5,376 KB
testcase_21 AC 3 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 145 ms
5,376 KB
testcase_24 AC 83 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 1 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 WA -
testcase_29 AC 4 ms
5,376 KB
testcase_30 WA -
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 6 ms
5,376 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(nu == nl){
            // 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