結果
問題 | No.120 傾向と対策:門松列(その1) |
ユーザー |
![]() |
提出日時 | 2019-04-05 01:17:43 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 59 ms / 5,000 ms |
コード長 | 1,169 bytes |
コンパイル時間 | 1,950 ms |
コンパイル使用メモリ | 179,668 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-29 14:03:02 |
合計ジャッジ時間 | 3,149 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 4 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i,n) REP(i,0,n) #define REP(i,s,e) for(int i=(s); i<(int)(e); i++) #define repr(i, n) REPR(i, n, 0) #define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--) #define pb push_back #define all(r) r.begin(),r.end() #define rall(r) r.rbegin(),r.rend() #define fi first #define se second typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int INF = 1e9; const ll MOD = 1e9 + 7; double EPS = 1e-8; int main(){ int t; cin >> t; while(t--) { int n; cin >> n; vector<int> v(n); rep(i, n) cin >> v[i]; map<int, int> mp; rep(i, n) ++mp[v[i]]; priority_queue<int> q; for(auto&& p : mp) q.push(p.se); int ans = 0; while(q.size() >= 3) { auto a = q.top(); q.pop(); auto b = q.top(); q.pop(); auto c = q.top(); q.pop(); ++ans; if(a > 1) q.push(a-1); if(b > 1) q.push(b-1); if(c > 1) q.push(c-1); } cout << ans << endl; } return 0; }