結果
| 問題 |
No.120 傾向と対策:門松列(その1)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-09-16 15:57:38 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 59 ms / 5,000 ms |
| コード長 | 593 bytes |
| コンパイル時間 | 859 ms |
| コンパイル使用メモリ | 86,860 KB |
| 最終ジャッジ日時 | 2025-02-07 05:51:52 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 4 |
ソースコード
#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();
}
}