結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー yuppe19 😺yuppe19 😺
提出日時 2015-07-02 14:02:31
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 29 ms / 5,000 ms
コード長 1,029 bytes
コンパイル時間 839 ms
コンパイル使用メモリ 79,648 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-22 05:33:18
合計ジャッジ時間 1,404 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
4,380 KB
testcase_01 AC 28 ms
4,380 KB
testcase_02 AC 15 ms
4,380 KB
testcase_03 AC 29 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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