結果
問題 | No.120 傾向と対策:門松列(その1) |
ユーザー |
![]() |
提出日時 | 2020-11-22 04:05:05 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 25 ms / 5,000 ms |
コード長 | 860 bytes |
コンパイル時間 | 2,229 ms |
コンパイル使用メモリ | 204,596 KB |
最終ジャッジ日時 | 2025-01-16 04:16:38 |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 4 |
ソースコード
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> bool cmin(T &a, U b) { return a > b && (a = b, true); } template <typename T, typename U> bool cmax(T &a, U b) { return a < b && (a = b, true); } signed main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); int T; cin >> T; while (T--) { int N; cin >> N; vector<int> L(N); for (int i = 0; i < N; i++) cin >> L.at(i); map<int, int> MA; for (auto a : L) MA[a]++; priority_queue<int> PQ; for (auto [a, b] : MA) PQ.push(b); int ans = 0; while (PQ.size() >= 3) { int a = PQ.top(); PQ.pop(); int b = PQ.top(); PQ.pop(); int c = PQ.top(); PQ.pop(); a--; if (a) PQ.push(a); b--; if (b) PQ.push(b); c--; if (c) PQ.push(c); ans++; } cout << ans << "\n"; } }