結果
問題 | No.9 モンスターのレベル上げ |
ユーザー |
|
提出日時 | 2016-09-01 00:31:49 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 1,084 ms / 5,000 ms |
コード長 | 966 bytes |
コンパイル時間 | 1,047 ms |
コンパイル使用メモリ | 127,192 KB |
実行使用メモリ | 6,400 KB |
最終ジャッジ日時 | 2024-06-12 04:04:00 |
合計ジャッジ時間 | 10,805 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 20 |
ソースコード
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 r = iota(n).map!(i => bi[i..$] ~ bi[0..i]).map!(bi => calcCount(ai, bi)).reduce!(min); writeln(r); } long calcCount(long[] ai, long[] bi) { auto mi = ai.map!(a => monster(a, 0)).array; auto hi = mi.heapify!("a > b"); foreach (b; bi) { auto h = hi.front; hi.replaceFront(monster(h.level + b / 2, h.count + 1)); } return hi.map!("a.count").reduce!(max); }