結果

問題 No.120 傾向と対策:門松列(その1)
コンテスト
ユーザー te-sh
提出日時 2017-01-30 16:02:30
言語 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  
実行時間 32 ms / 5,000 ms
コード長 579 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 705 ms
コンパイル使用メモリ 92,456 KB
実行使用メモリ 7,712 KB
最終ジャッジ日時 2026-03-05 11:51:54
合計ジャッジ時間 1,351 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 4
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import std.algorithm, std.conv, std.range, std.stdio, std.string;

void main()
{
  auto t = readln.chomp.to!size_t;

  foreach (_; t.iota) {
    auto n = readln.chomp.to!int;
    auto li = readln.split.to!(int[]);

    auto calc(int[] li) {
      int[int] cnt;
      foreach (l; li) ++cnt[l];

      auto ci = cnt.values;
      if (ci.length < 3) return 0;
      ci.sort!"a > b";

      auto k1 = ci[0];
      if (k1 <= n / 3) return n / 3;

      auto k2 = ci[1];
      if (k2 <= (n - k1) / 2) return (n - k1) / 2;

      return n - k1 - k2;
    }

    writeln(calc(li));
  }
}
0