結果
| 問題 |
No.120 傾向と対策:門松列(その1)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-08-30 22:24:17 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
AC
|
| 実行時間 | 39 ms / 5,000 ms |
| コード長 | 693 bytes |
| コンパイル時間 | 932 ms |
| コンパイル使用メモリ | 130,676 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-12 03:53:28 |
| 合計ジャッジ時間 | 1,446 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 4 |
ソースコード
import std.algorithm, std.array, std.container, std.range;
import std.string, std.conv;
import std.math, std.bigint, std.bitmanip, std.random;
import std.stdio, std.typecons;
const auto mod = 10 ^^ 9 + 7;
void main()
{
auto t = readln.chomp.to!int;
foreach (_; 0..t) {
auto n = readln.chomp.to!int;
auto ai = readln.split.map!(to!int).array;
ai.sort();
auto hi = heapify(ai.group.map!("a[1].to!int").array);
writeln(calc(hi, 0));
}
}
int calc(BinaryHeap!(int[]) hi, int acc)
{
auto r = 0;
while (hi.length >= 3) {
auto ai = hi.take(3).array;
ai[] -= 1;
foreach (a; ai) {
if (a > 0)
hi.insert(a);
}
r += 1;
}
return r;
}