結果
| 問題 |
No.120 傾向と対策:門松列(その1)
|
| コンテスト | |
| ユーザー |
koyumeishi
|
| 提出日時 | 2015-01-09 00:08:04 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 56 ms / 5,000 ms |
| コード長 | 948 bytes |
| コンパイル時間 | 801 ms |
| コンパイル使用メモリ | 88,940 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-13 03:24:02 |
| 合計ジャッジ時間 | 1,474 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 4 |
ソースコード
#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
using namespace std;
int main(){
int T;
cin >> T;
for(int t=0; t<T; t++){
int N;
cin >> N;
vector<int> L(N);
for(int i=0; i<N; i++) cin >> L[i];
map<int, int> m;
for(int i=0; i<N; i++){
m[L[i]]++;
}
vector< pair<int,int> > v;
for(auto itr = m.begin(); itr!=m.end(); itr++){
v.push_back( {itr->second, itr->first} );
}
priority_queue< pair<int,int> > pq(v.begin(), v.end());
int ans = 0;
while(pq.size() >= 3){
auto a = pq.top(); pq.pop();
auto b = pq.top(); pq.pop();
auto c = pq.top(); pq.pop();
ans++;
if(a.first > 1){
pq.push( {a.first-1, a.second} );
}
if(b.first > 1){
pq.push( {b.first-1, b.second} );
}
if(c.first > 1){
pq.push( {c.first-1, c.second} );
}
}
cout << ans << endl;
}
return 0;
}
koyumeishi