結果

問題 No.451 575
ユーザー crazybbb3crazybbb3
提出日時 2016-12-05 20:12:27
言語 Java21
(openjdk 21)
結果
AC  
実行時間 396 ms / 2,000 ms
コード長 2,600 bytes
コンパイル時間 2,320 ms
コンパイル使用メモリ 75,488 KB
実行使用メモリ 61,304 KB
最終ジャッジ日時 2023-08-22 13:48:30
合計ジャッジ時間 9,919 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,428 KB
testcase_01 AC 43 ms
49,380 KB
testcase_02 AC 42 ms
49,624 KB
testcase_03 AC 42 ms
49,508 KB
testcase_04 AC 43 ms
49,696 KB
testcase_05 AC 96 ms
52,500 KB
testcase_06 AC 128 ms
55,224 KB
testcase_07 AC 226 ms
58,168 KB
testcase_08 AC 43 ms
49,628 KB
testcase_09 AC 71 ms
51,584 KB
testcase_10 AC 220 ms
56,056 KB
testcase_11 AC 340 ms
60,372 KB
testcase_12 AC 396 ms
60,552 KB
testcase_13 AC 380 ms
60,472 KB
testcase_14 AC 47 ms
47,756 KB
testcase_15 AC 104 ms
52,936 KB
testcase_16 AC 133 ms
55,112 KB
testcase_17 AC 245 ms
57,740 KB
testcase_18 AC 225 ms
57,508 KB
testcase_19 AC 202 ms
56,792 KB
testcase_20 AC 123 ms
53,188 KB
testcase_21 AC 83 ms
51,972 KB
testcase_22 AC 43 ms
49,544 KB
testcase_23 AC 367 ms
61,304 KB
testcase_24 AC 293 ms
60,420 KB
testcase_25 AC 44 ms
49,440 KB
testcase_26 AC 42 ms
47,744 KB
testcase_27 AC 55 ms
50,708 KB
testcase_28 AC 64 ms
51,504 KB
testcase_29 AC 125 ms
52,588 KB
testcase_30 AC 236 ms
57,828 KB
testcase_31 AC 42 ms
49,444 KB
testcase_32 AC 141 ms
55,272 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class Main {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    void solve() throws IOException {
        int n = ni();
        long[] b = nla(n);

        long l = 1;
        long h = b[0] - 1;

        for (int i = 0; i < n; i++) {
            if (i % 2 == 0) {
                long tl = b[i] - h;
                long th = b[i] - l;
                l = tl;
                h = th;
            } else {
                long tl = l - b[i];
                long th = h - b[i];
                l = tl;
                h = th;
            }

            if (h <= 0) {
                out.println(-1);
                return;
            }

            l = Math.max(l, 1);
        }

        ArrayList<Long> list = new ArrayList<>();
        list.add(h);
        for (int i = n - 1; i >= 0; i--) {
            if (i % 2 == 0) {
                list.add(b[i] - list.get(n - 1 - i));
            } else {
                list.add(b[i] + list.get(n - 1 - i));
            }
        }

        out.println(n + 1);
        for (int i = n; i >= 0; i--) {
            out.println(list.get(i));
        }
    }

    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }

    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }

    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}
0