結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー CleyLCleyL
提出日時 2022-09-16 15:57:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 51 ms / 5,000 ms
コード長 593 bytes
コンパイル時間 896 ms
コンパイル使用メモリ 91,096 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-23 10:34:09
合計ジャッジ時間 1,742 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <queue>
using namespace std;
void solve(){
  int n;cin>>n;
  map<int,int> A;
  for(int i = 0; n > i; i++){
    int x;cin>>x;
    A[x]++;
  }
  priority_queue<int> B;
  for(auto x: A){
    B.push(x.second);
  }
  int ans = 0;
  while(B.size() >= 3){
    auto a1 = B.top();B.pop();
    auto a2 = B.top();B.pop();
    auto a3 = B.top();B.pop();
    if(--a1)B.push(a1);
    if(--a2)B.push(a2);
    if(--a3)B.push(a3);
    ans++;
  }
  cout << ans << endl;
}
int main(){
  int t;cin>>t;
  for(int i = 0; t > i; i++){
    solve();
  }
}
0