結果
| 問題 |
No.120 傾向と対策:門松列(その1)
|
| コンテスト | |
| ユーザー |
Tatsu_mr
|
| 提出日時 | 2024-11-02 18:40:26 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 78 ms / 5,000 ms |
| コード長 | 1,411 bytes |
| コンパイル時間 | 3,601 ms |
| コンパイル使用メモリ | 258,572 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-02 18:40:30 |
| 合計ジャッジ時間 | 4,398 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 4 |
ソースコード
#include <bits/stdc++.h>
#define For(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) For(i, 0, n)
#define rFor(i, a, b) for(int i = a; i >= b; i--)
#define ALL(v) (v).begin(), (v).end()
#define rALL(v) (v).rbegin(), (v).rend()
using namespace std;
using lint = long long;
using ld = long double;
int INF = 2000000000;
lint LINF = 1000000000000000000;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
map<int, int> mp;
rep(_, n) {
int l;
cin >> l;
mp[l]++;
}
multiset<pair<int, int>> s;
for (auto [fi, se] : mp) {
s.insert({se, fi});
}
int ans = 0;
while (s.size() >= 3) {
auto it = s.end();
it--;
auto [a, ia] = *it;
it--;
auto [b, ib] = *it;
it--;
auto [c, ic] = *it;
ans++;
s.erase(s.find({a, ia}));
mp[ia]--;
if (mp[ia] > 0) {
s.insert({mp[ia], ia});
}
s.erase(s.find({b, ib}));
mp[ib]--;
if (mp[ib] > 0) {
s.insert({mp[ib], ib});
}
s.erase(s.find({c, ic}));
mp[ic]--;
if (mp[ic] > 0) {
s.insert({mp[ic], ic});
}
}
cout << ans << endl;
}
}
Tatsu_mr