結果

問題 No.180 美しいWhitespace (2)
ユーザー te-shte-sh
提出日時 2016-09-15 15:37:21
言語 D
(dmd 2.105.2)
結果
AC  
実行時間 27 ms / 5,000 ms
コード長 948 bytes
コンパイル時間 903 ms
コンパイル使用メモリ 111,644 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-09-02 22:10:49
合計ジャッジ時間 2,943 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,368 KB
testcase_01 AC 1 ms
4,372 KB
testcase_02 AC 2 ms
4,372 KB
testcase_03 AC 1 ms
4,372 KB
testcase_04 AC 3 ms
4,372 KB
testcase_05 AC 5 ms
4,372 KB
testcase_06 AC 6 ms
4,368 KB
testcase_07 AC 8 ms
4,368 KB
testcase_08 AC 8 ms
4,368 KB
testcase_09 AC 2 ms
4,368 KB
testcase_10 AC 2 ms
4,368 KB
testcase_11 AC 24 ms
4,372 KB
testcase_12 AC 23 ms
4,368 KB
testcase_13 AC 19 ms
4,368 KB
testcase_14 AC 17 ms
4,368 KB
testcase_15 AC 14 ms
4,368 KB
testcase_16 AC 12 ms
4,368 KB
testcase_17 AC 8 ms
4,368 KB
testcase_18 AC 6 ms
4,368 KB
testcase_19 AC 3 ms
4,372 KB
testcase_20 AC 2 ms
4,372 KB
testcase_21 AC 1 ms
4,372 KB
testcase_22 AC 1 ms
4,368 KB
testcase_23 AC 1 ms
4,372 KB
testcase_24 AC 2 ms
4,368 KB
testcase_25 AC 2 ms
4,372 KB
testcase_26 AC 1 ms
4,368 KB
testcase_27 AC 1 ms
4,372 KB
testcase_28 AC 2 ms
4,368 KB
testcase_29 AC 2 ms
4,372 KB
testcase_30 AC 14 ms
4,372 KB
testcase_31 AC 17 ms
4,368 KB
testcase_32 AC 3 ms
4,372 KB
testcase_33 AC 24 ms
4,372 KB
testcase_34 AC 27 ms
4,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.array, std.container, std.range, std.bitmanip;
import std.numeric, std.math, std.bigint, std.random, core.bitop;
import std.string, std.regex, std.conv, std.stdio, std.typecons;

void main()
{
  auto n = readln.chomp.to!size_t;
  auto li = iota(n).map!(_ => readln.split.map!(to!long)).array;

  long calc(long x) {
    auto s = li.map!(l => l[0] + l[1] * x);
    return s.reduce!(max) - s.reduce!(min);
  }

  auto r0 = calc(1);
  auto r1 = calc(2);
  if (r0 < r1) {
    writeln(1);
    return;
  }

  auto mi = 1L, ma = 2L;
  while (r0 > calc(ma)) ma <<= 1;
  while (ma - mi > 2) {
    auto mt1 = (mi * 2 + ma) / 3;
    auto mt2 = (mi + ma * 2) / 3;
    auto rt1 = calc(mt1);
    auto rt2 = calc(mt2);
    if (rt1 > rt2)
      mi = mt1;
    else
      ma = mt2;
  }

  auto r = long.max, m = 0L;
  foreach (mc; mi..ma+1) {
    auto rc = calc(mc);
    if (rc < r) {
      r = rc;
      m = mc;
    }
  }

  writeln(m);
}
0