結果
問題 | No.120 傾向と対策:門松列(その1) |
ユーザー |
![]() |
提出日時 | 2015-04-08 00:57:48 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 56 ms / 5,000 ms |
コード長 | 661 bytes |
コンパイル時間 | 1,470 ms |
コンパイル使用メモリ | 171,532 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-04 10:58:47 |
合計ジャッジ時間 | 2,110 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 4 |
ソースコード
#include "bits/stdc++.h"using namespace std;void calc() {int N;cin >> N;vector<int> L(N);long long sum = 0;map<int, int> m;for (int i = 0; i < N; i++){cin >> L[i];sum += L[i];m[L[i]]++;}priority_queue<int> pq;for (auto i : m){pq.push(i.second);}if (m.size() < 3){cout << 0 << endl;return;}int ans = 0;while (true){int a = pq.top(); pq.pop();int b = pq.top(); pq.pop();int c = pq.top(); pq.pop();if (c <= 0){cout << ans << endl;return;}ans++;pq.push(a - 1);pq.push(b - 1);pq.push(c - 1);}}int main(){int T;cin >> T;for (int i = 0; i < T; i++){calc();}}