結果

問題 No.451 575
ユーザー crazybbb3crazybbb3
提出日時 2016-12-05 20:04:29
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,566 bytes
コンパイル時間 2,327 ms
コンパイル使用メモリ 78,760 KB
実行使用メモリ 62,692 KB
最終ジャッジ日時 2024-05-09 19:11:29
合計ジャッジ時間 11,164 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
36,772 KB
testcase_01 WA -
testcase_02 AC 43 ms
36,952 KB
testcase_03 AC 45 ms
37,176 KB
testcase_04 AC 42 ms
36,876 KB
testcase_05 AC 98 ms
39,508 KB
testcase_06 AC 120 ms
41,232 KB
testcase_07 AC 211 ms
46,548 KB
testcase_08 AC 43 ms
36,952 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 218 ms
47,076 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 44 ms
37,084 KB
testcase_27 AC 47 ms
37,108 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 42 ms
37,048 KB
testcase_32 AC 135 ms
43,528 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;
            }
        }

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

        out.println(n + 1);
        for (int i = 0; i <= n; i++) {
            out.println(list.get(n - 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