結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー te-shte-sh
提出日時 2016-08-30 22:24:17
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 42 ms / 5,000 ms
コード長 693 bytes
コンパイル時間 835 ms
コンパイル使用メモリ 117,408 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-09-02 21:38:19
合計ジャッジ時間 1,555 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
4,368 KB
testcase_01 AC 41 ms
4,372 KB
testcase_02 AC 21 ms
4,368 KB
testcase_03 AC 42 ms
4,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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