結果
問題 | No.451 575 |
ユーザー |
|
提出日時 | 2016-12-17 00:58:52 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 1,291 ms / 2,000 ms |
コード長 | 1,316 bytes |
コンパイル時間 | 3,364 ms |
コンパイル使用メモリ | 77,952 KB |
実行使用メモリ | 77,128 KB |
最終ジャッジ日時 | 2024-12-17 13:20:21 |
合計ジャッジ時間 | 19,353 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 29 |
ソースコード
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(); } }