結果

問題 No.120 傾向と対策:門松列(その1)
コンテスト
ユーザー te-sh
提出日時 2016-08-30 22:24:17
言語 D
(dmd 2.112.0)
コンパイル:
dmd -fPIE -m64 -w -wi -O -release -inline -I/opt/dmd/src/druntime/import/ -I/opt/dmd/src/phobos -L-L/opt/dmd/linux/lib64/ -fPIC _filename_
実行:
./Main
結果
AC  
実行時間 42 ms / 5,000 ms
コード長 693 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 750 ms
コンパイル使用メモリ 110,628 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2026-03-05 07:11:11
合計ジャッジ時間 1,291 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 4
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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;
}
0