結果

問題 No.451 575
ユーザー 37zigen37zigen
提出日時 2016-12-02 02:09:19
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,758 bytes
コンパイル時間 3,255 ms
コンパイル使用メモリ 79,312 KB
実行使用メモリ 59,952 KB
最終ジャッジ日時 2024-05-09 18:14:10
合計ジャッジ時間 18,127 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 109 ms
41,544 KB
testcase_01 AC 113 ms
41,064 KB
testcase_02 AC 103 ms
39,896 KB
testcase_03 AC 101 ms
39,824 KB
testcase_04 AC 102 ms
39,836 KB
testcase_05 AC 208 ms
45,828 KB
testcase_06 AC 322 ms
48,260 KB
testcase_07 AC 639 ms
53,172 KB
testcase_08 AC 106 ms
40,064 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 1,183 ms
59,952 KB
testcase_14 WA -
testcase_15 AC 212 ms
45,148 KB
testcase_16 AC 340 ms
48,116 KB
testcase_17 AC 638 ms
52,980 KB
testcase_18 WA -
testcase_19 AC 566 ms
49,324 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 113 ms
41,348 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 120 ms
41,224 KB
testcase_26 WA -
testcase_27 AC 154 ms
41,660 KB
testcase_28 AC 176 ms
42,316 KB
testcase_29 AC 273 ms
47,368 KB
testcase_30 AC 599 ms
53,044 KB
testcase_31 AC 103 ms
40,152 KB
testcase_32 AC 413 ms
48,592 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;

import java.util.*;

public class Q451 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] b = new long[n + 1];
		long[] a = new long[n + 2];
		long Max = 1_000_000_000_000_000_000L;
		for (int i = 1; i <= n; ++i) {
			b[i] = sc.nextLong();
			if ((i + 1) % 2 == 0)
				a[i + 1] += b[i];
			else
				a[i + 1] -= b[i];
		}
		a[1] = 1;
		for (int i = 2; i <= n + 1; ++i) {
			if (i % 2 == 0) {
				a[i] -= a[i - 1];
			} else {
				a[i] += a[i - 1];
			}
			if (a[i] > 2 * Max || a[i] < -Max) {
				System.out.println(-1);
				return;
			}
		}

		long oddMax = -Long.MAX_VALUE;
		long oddMin = Long.MAX_VALUE;
		long evenMax = -Long.MAX_VALUE;
		long evenMin = Long.MAX_VALUE;
		for (int i = 1; i <= n + 1; ++i) {
			if (i % 2 == 1) {
				oddMax = Math.max(oddMax, a[i]);
				oddMin = Math.min(oddMin, a[i]);
			} else {
				evenMax = Math.max(evenMax, a[i]);
				evenMin = Math.min(evenMin, a[i]);
			}
		}

		ArrayDeque<Long> que = new ArrayDeque<>();
		// oddにどれだけ加算するか
		que.add(Max - oddMax);
		que.add(-Max + evenMax);
		que.add(1 - oddMin);
		que.add(-1 + evenMin);
		while (!que.isEmpty()) {
			long add = que.poll();
			if (oddMax + add <= Max && oddMax + add > 0 && evenMax - add <= Max && evenMax - add > 0 && oddMin + add > 0
					&& oddMin + add <= Max && evenMin - add > 0 && evenMin - add <= Max) {
				System.out.println(n + 1);
				for (int i = 1; i <= n + 1; ++i) {
					if (i % 2 == 1) {
						System.out.println(a[i] + add);
					} else {
						System.out.println(a[i] - add);
					}
				}
				return;
			}
		}
		System.out.println(-1);

	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}
0