結果
| 問題 |
No.120 傾向と対策:門松列(その1)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-05-11 21:28:02 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 58 ms / 5,000 ms |
| コード長 | 980 bytes |
| コンパイル時間 | 649 ms |
| コンパイル使用メモリ | 80,920 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-05 23:12:10 |
| 合計ジャッジ時間 | 1,269 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 4 |
ソースコード
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <map>
#include <queue>
using namespace std;
int main() {
int t, n, l;
cin >> t;
vector<int> ans(t, 0);
for (int i = 0; i < t; i++) {
cin >> n;
map<int, int> banboo;
for (int j = 0; j < n; j++) {
cin >> l;
if (banboo.count(l) > 0) {
banboo[l]++;
} else {
banboo[l] = 1;
}
}
priority_queue< pair<int , int> > que;
for (auto it = banboo.begin(); it != banboo.end(); it++) {
que.push(make_pair((*it).second, (*it).first));
}
while (que.size() >= 3) {
ans[i]++;
auto q1 = que.top(); que.pop();
auto q2 = que.top(); que.pop();
auto q3 = que.top(); que.pop();
q1.first--;
q2.first--;
q3.first--;
if (q1.first > 0) { que.push(q1); }
if (q2.first > 0) { que.push(q2); }
if (q3.first > 0) { que.push(q3); }
}
}
for (int i = 0; i < t; i++) {
cout << ans[i] << endl;
}
return 0;
}