結果
問題 | No.120 傾向と対策:門松列(その1) |
ユーザー |
|
提出日時 | 2024-09-22 15:31:56 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 29 ms / 5,000 ms |
コード長 | 723 bytes |
コンパイル時間 | 2,007 ms |
コンパイル使用メモリ | 204,608 KB |
最終ジャッジ日時 | 2025-02-24 11:31:49 |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 4 |
ソースコード
#include<bits/stdc++.h> using namespace std; using ll=long long; int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); ll T; cin>>T; while(T--){ ll N; cin>>N; map<ll,ll> L; for(int i=0;i<N;i++){ ll a; cin>>a; L[a]++; } priority_queue<ll> Q; for(auto p:L)Q.push(p.second); ll an=0; while(Q.size()>2){ vector<ll> V; for(int i=0;i<3;i++){ V.push_back(Q.top()); Q.pop(); } an++; for(int i=0;i<3;i++){ if(V[i]>1)Q.push(V[i]-1); } } cout<<an<<endl; } }