結果

問題 No.120 傾向と対策:門松列(その1)
コンテスト
ユーザー yuppe19 😺
提出日時 2015-07-02 14:02:31
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 17 ms / 5,000 ms
コード長 1,029 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 603 ms
コンパイル使用メモリ 101,740 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2026-03-29 13:35:38
合計ジャッジ時間 1,092 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 4
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
using namespace std;

class range {private: struct I{int x;int operator*(){return x;}bool operator!=(I& lhs){return x<lhs.x;}void operator++(){++x;}};I i,n;
public:range(int n):i({0}),n({n}){}range(int i,int n):i({i}),n({n}){}I& begin(){return i;}I& end(){return n;}};

int nya(priority_queue<int> que) {
  if(que.size() < 3) { return 0; }
  int res = 0;
  while(!que.empty()) {
    int x = que.top(); que.pop();
    int y = que.top(); que.pop();
    int z = que.top(); que.pop();
    if(z == 0) { break; }
    res++;
    que.push(x-1);
    que.push(y-1);
    que.push(z-1);
  }
  return res;
}

int main(void) {
  int t; scanf("%d", &t);
  for(int times : range(t)) {
    int n; scanf("%d", &n);
    map<int, int> kort;
    for(int i : range(n)) {
      int x; scanf("%d", &x);
      kort[x]++;
    }
    priority_queue<int> que;
    for(auto kv : kort) {
      que.push(kv.second);
    }
    int res = nya(que);
    printf("%d\n", res);
  }
  return 0;
}
0