結果

問題 No.451 575
ユーザー te-shte-sh
提出日時 2017-12-01 15:40:20
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 117 ms / 2,000 ms
コード長 821 bytes
コンパイル時間 852 ms
コンパイル使用メモリ 92,076 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2023-09-03 17:07:54
合計ジャッジ時間 5,371 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 6 ms
4,380 KB
testcase_07 AC 26 ms
5,944 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 19 ms
4,380 KB
testcase_11 AC 54 ms
4,932 KB
testcase_12 AC 72 ms
5,172 KB
testcase_13 AC 58 ms
5,640 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 8 ms
4,380 KB
testcase_17 AC 41 ms
5,168 KB
testcase_18 AC 26 ms
6,144 KB
testcase_19 AC 30 ms
5,900 KB
testcase_20 AC 4 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 117 ms
5,192 KB
testcase_24 AC 70 ms
4,600 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 7 ms
4,376 KB
testcase_30 AC 61 ms
6,400 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 10 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.conv, std.range, std.stdio, std.string;
import std.typecons;  // Tuple, Nullable, BigFlags

void main()
{
  auto n = readln.chomp.to!int;
  auto b = new long[](n);
  foreach (i; 0..n) b[i] = readln.chomp.to!long;

  auto a = new long[](n+1);

  auto calc(long a0)
  {
    a[0] = a0;
    foreach (i; 1..n+1) {
      a[i] = (i&1) ? b[i-1]-a[i-1] : a[i-1]-b[i-1];
      if (a[i] < 1)
        return (((i-1)/2)&1) ? -1 : 1;
      else if (a[i] > 10L^^18)
        return (((i-1)/2)&1) ? 1 : -1;
    }
    return 0;
  }

  auto bsearch = iota(1, 10L^^18).map!(a0 => tuple(a0, calc(a0))).assumeSorted!"a[1] < b[1]";
  auto r = bsearch.equalRange(tuple(0, 0));
  if (r.empty) {
    writeln(-1);
  } else {
    auto a0 = r.front[0];
    calc(a0);
    writeln(n+1);
    foreach (ai; a) writeln(ai);
  }
}
0