結果
問題 | No.451 575 |
ユーザー | zimpha |
提出日時 | 2017-03-31 22:14:05 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 373 ms / 2,000 ms |
コード長 | 2,970 bytes |
コンパイル時間 | 2,243 ms |
コンパイル使用メモリ | 78,496 KB |
実行使用メモリ | 57,952 KB |
最終ジャッジ日時 | 2024-07-07 04:48:38 |
合計ジャッジ時間 | 8,653 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 47 ms
50,576 KB |
testcase_01 | AC | 47 ms
50,520 KB |
testcase_02 | AC | 47 ms
50,336 KB |
testcase_03 | AC | 48 ms
50,524 KB |
testcase_04 | AC | 48 ms
50,460 KB |
testcase_05 | AC | 101 ms
52,264 KB |
testcase_06 | AC | 125 ms
54,716 KB |
testcase_07 | AC | 238 ms
57,508 KB |
testcase_08 | AC | 48 ms
50,640 KB |
testcase_09 | AC | 82 ms
51,176 KB |
testcase_10 | AC | 189 ms
55,684 KB |
testcase_11 | AC | 330 ms
57,812 KB |
testcase_12 | AC | 373 ms
57,460 KB |
testcase_13 | AC | 371 ms
57,952 KB |
testcase_14 | AC | 52 ms
50,288 KB |
testcase_15 | AC | 103 ms
52,392 KB |
testcase_16 | AC | 130 ms
54,988 KB |
testcase_17 | AC | 247 ms
57,456 KB |
testcase_18 | AC | 232 ms
57,692 KB |
testcase_19 | AC | 231 ms
56,248 KB |
testcase_20 | AC | 123 ms
52,672 KB |
testcase_21 | AC | 96 ms
51,792 KB |
testcase_22 | AC | 47 ms
50,532 KB |
testcase_23 | AC | 344 ms
57,288 KB |
testcase_24 | AC | 294 ms
57,556 KB |
testcase_25 | AC | 51 ms
50,560 KB |
testcase_26 | AC | 49 ms
50,128 KB |
testcase_27 | AC | 54 ms
50,232 KB |
testcase_28 | AC | 70 ms
51,488 KB |
testcase_29 | AC | 128 ms
52,768 KB |
testcase_30 | AC | 246 ms
57,796 KB |
testcase_31 | AC | 48 ms
50,364 KB |
testcase_32 | AC | 148 ms
55,348 KB |
ソースコード
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Chiaki.Hoshinomori */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); Task451 solver = new Task451(); solver.solve(1, in, out); out.close(); } static class Task451 { public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(); long[] b = in.nextLongArray(n); long l = 1, r = 1000000000000000000l; for (int i = 0; i < n; i++) { long ll = 0, rr = 0; if (i % 2 == 0) { ll = b[i] - r; rr = b[i] - l; } else { ll = l - b[i]; rr = r - b[i]; } l = Math.max(1, ll); r = Math.min(rr, 1000000000000000000l); if (l > r) { out.println("-1"); return; } } long[] a = new long[n + 1]; a[n] = l; for (int i = n; i > 0; i--) { if (i % 2 == 1) { a[i - 1] = b[i - 1] - a[i]; } else { a[i - 1] = b[i - 1] + a[i]; } } out.println(n + 1); for (int i = 0; i <= n; i++) { out.println(a[i]); } } } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public long[] nextLongArray(int n) { long[] r = new long[n]; for (int i = 0; i < n; i++) { r[i] = nextLong(); } return r; } } }