結果
問題 | No.120 傾向と対策:門松列(その1) |
ユーザー |
|
提出日時 | 2022-10-04 20:32:32 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 24 ms / 5,000 ms |
コード長 | 789 bytes |
コンパイル時間 | 1,900 ms |
コンパイル使用メモリ | 204,728 KB |
最終ジャッジ日時 | 2025-02-07 21:24:21 |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 4 |
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main(){ cin.tie(0); ios::sync_with_stdio(0); int T; cin >> T; rep(_,T) { int N; cin >> N; map<int,int> mp; rep(i,N) { int L; cin >> L; mp[L]++; } priority_queue<int> pq; for(auto [_, c] : mp) pq.push(c); int ans = 0; while(int(pq.size()) >= 3) { int a = pq.top(); pq.pop(); int b = pq.top(); pq.pop(); int c = pq.top(); pq.pop(); a--; b--; c--; ans++; if(a > 0) pq.push(a); if(b > 0) pq.push(b); if(c > 0) pq.push(c); } cout << ans << "\n"; } }