結果
| 問題 |
No.120 傾向と対策:門松列(その1)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-12-22 21:18:17 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 29 ms / 5,000 ms |
| コード長 | 555 bytes |
| コンパイル時間 | 2,148 ms |
| コンパイル使用メモリ | 178,420 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-12-14 14:53:52 |
| 合計ジャッジ時間 | 2,320 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 4 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main() {
int T;
cin >> T;
while (T--) {
int n;
cin >> n;
map<int, int> mp;
for (int i = 0; i < n; i++) {
int a;
scanf("%d", &a);
mp[a]++;
}
priority_queue<int> q;
for (auto kv : mp) {
q.push(kv.second);
}
int ans = 0;
while (q.size() >= 3) {
int x = q.top(); q.pop();
int y = q.top(); q.pop();
int z = q.top(); q.pop();
if (x - 1 > 0) q.push(x - 1);
if (y - 1 > 0) q.push(y - 1);
if (z - 1 > 0) q.push(z - 1);
ans++;
}
cout << ans << endl;
}
}