結果

問題 No.451 575
ユーザー hermione17
提出日時 2016-12-17 00:20:38
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 1,146 bytes
コンパイル時間 3,815 ms
コンパイル使用メモリ 77,348 KB
実行使用メモリ 71,460 KB
最終ジャッジ日時 2024-07-19 16:19:56
合計ジャッジ時間 18,609 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 21 WA * 8
権限があれば一括ダウンロードができます

ソースコード

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] + 1);
			}
			if (a[i] > INF && (i % 4 == 1 || i % 4 == 2)) {
				a[0] = Math.max(a[0], a[i] - INF + 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 = 0; i <= n; i++) {
			if (a[i] < 1 || INF < a[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