結果

問題 No.9 モンスターのレベル上げ
ユーザー te-shte-sh
提出日時 2016-09-01 00:36:57
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 562 ms / 5,000 ms
コード長 1,002 bytes
コンパイル時間 852 ms
コンパイル使用メモリ 113,084 KB
実行使用メモリ 6,736 KB
最終ジャッジ日時 2023-09-02 21:49:43
合計ジャッジ時間 6,540 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,368 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 AC 562 ms
6,680 KB
testcase_03 AC 440 ms
6,672 KB
testcase_04 AC 238 ms
6,712 KB
testcase_05 AC 156 ms
6,708 KB
testcase_06 AC 56 ms
6,656 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 73 ms
6,652 KB
testcase_09 AC 548 ms
6,672 KB
testcase_10 AC 1 ms
4,372 KB
testcase_11 AC 337 ms
6,716 KB
testcase_12 AC 302 ms
6,668 KB
testcase_13 AC 234 ms
6,712 KB
testcase_14 AC 545 ms
6,676 KB
testcase_15 AC 496 ms
6,736 KB
testcase_16 AC 10 ms
4,368 KB
testcase_17 AC 321 ms
6,664 KB
testcase_18 AC 272 ms
6,720 KB
testcase_19 AC 6 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;
import std.string, std.conv, std.stdio, std.typecons;

struct monster {
  long level;
  long count;

  int opCmp(monster rhs) {
    int sign(long n) {
      return n == 0 ? 0 : (n > 0 ? 1 : -1);
    }
    auto s1 = sign(level - rhs.level);
    auto s2 = sign(count - rhs.count);
    return s1 == 0 ? s2 : s1;
  }
}

void main()
{
  auto n = readln.chomp.to!int;
  auto ai = readln.split.map!(to!long).array;
  auto bi = readln.split.map!(to!long).array;

  auto m = long.max;
  foreach (ci; iota(n).map!(i => bi[i..$] ~ bi[0..i]))
    m = min(m, calcCount(ai, ci));
    
  writeln(m);
}

long calcCount(long[] ai, long[] bi)
{
  auto mi = ai.map!(a => monster(a, 0)).array;
  auto hi = mi.heapify!("a > b");

  auto r = 0L;
  foreach (b; bi) {
    auto h = hi.front;
    hi.replaceFront(monster(h.level + b / 2, h.count + 1));
    r = max(r, h.count + 1);
  }

  return r;
}
0