結果

問題 No.451 575
ユーザー hermione17hermione17
提出日時 2016-12-17 00:58:52
言語 Java19
(openjdk 21)
結果
AC  
実行時間 1,297 ms / 2,000 ms
コード長 1,316 bytes
コンパイル時間 4,669 ms
コンパイル使用メモリ 73,840 KB
実行使用メモリ 81,848 KB
最終ジャッジ日時 2023-08-22 14:11:45
合計ジャッジ時間 19,814 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
55,616 KB
testcase_01 AC 120 ms
55,676 KB
testcase_02 AC 120 ms
55,996 KB
testcase_03 AC 121 ms
55,876 KB
testcase_04 AC 120 ms
56,076 KB
testcase_05 AC 225 ms
59,660 KB
testcase_06 AC 334 ms
60,424 KB
testcase_07 AC 609 ms
63,412 KB
testcase_08 AC 122 ms
56,036 KB
testcase_09 AC 219 ms
56,580 KB
testcase_10 AC 577 ms
60,800 KB
testcase_11 AC 1,134 ms
74,392 KB
testcase_12 AC 1,282 ms
80,708 KB
testcase_13 AC 1,284 ms
81,848 KB
testcase_14 AC 141 ms
55,832 KB
testcase_15 AC 215 ms
59,108 KB
testcase_16 AC 364 ms
60,604 KB
testcase_17 AC 632 ms
62,792 KB
testcase_18 AC 642 ms
62,628 KB
testcase_19 AC 536 ms
61,404 KB
testcase_20 AC 296 ms
60,176 KB
testcase_21 AC 229 ms
56,664 KB
testcase_22 AC 119 ms
55,684 KB
testcase_23 AC 1,297 ms
80,116 KB
testcase_24 AC 905 ms
70,780 KB
testcase_25 AC 123 ms
56,228 KB
testcase_26 AC 121 ms
55,932 KB
testcase_27 AC 174 ms
56,004 KB
testcase_28 AC 186 ms
56,152 KB
testcase_29 AC 300 ms
60,344 KB
testcase_30 AC 625 ms
63,472 KB
testcase_31 AC 119 ms
56,040 KB
testcase_32 AC 438 ms
62,672 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintStream;
import java.util.Scanner;

public class Y451 {
	Scanner in = new Scanner(System.in);
	PrintStream out = new PrintStream(System.out);

	Y451() throws Exception {
		int n = in.nextInt();
		long[] b = new long[n];
		for (int i = 0; i < n; i++) {
			b[i] = in.nextLong();
		}
		long[] a = new long[n+1];
		final long INF = 1000_000_000__000_000_000L;
				
		a[0] = 1;
		for (int i = 0; i < n; i++) {
			if (i % 2 == 0) {
				a[i+1] = b[i] - a[i];
			} else {
				a[i+1] = a[i] - b[i];
			}
		}
		
		for (int i = 1; i <= n; i++) {
			if (a[i] < 1 && (i % 4 == 0 || i % 4 == 3)) {
				a[0] = Math.max(a[0], -a[i] + 2);
			}
			if (a[i] > INF && (i % 4 == 1 || i % 4 == 2)) {
				a[0] = Math.max(a[0], a[i] - INF + 2);
			}
		}

		for (int i = 0; i < n; i++) {
			if (i % 2 == 0) {
				a[i+1] = b[i] - a[i];
			} else {
				a[i+1] = a[i] - b[i];
			}
		}
		
		for (int i = 0; i <= n; i++) {
			if (a[i] < 1 || INF < a[i]) {
				out.println(-1);
				return;
			}
		}
		for (int i = 0; i < n; i++) {
			if ((i % 2 == 0 && a[i] + a[i+1] != b[i]) ||
					(i % 2 == 1 && a[i] - a[i+1] != b[i])) {
				out.println(-1);
				return;
			}
		}
		out.println(n+1);
		for (int i = 0; i <= n; i++) {
			out.println(a[i]);
		}
	}

	public static void main(String argv[]) throws Exception {
		new Y451();
	}
}
0