結果
| 問題 |
No.120 傾向と対策:門松列(その1)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-05-21 17:32:34 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 929 bytes |
| コンパイル時間 | 866 ms |
| コンパイル使用メモリ | 86,516 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-28 15:29:20 |
| 合計ジャッジ時間 | 1,895 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | WA * 4 |
ソースコード
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
int t;
cin >> t;
while(t-- > 0){
int n, x;
cin >> n;
map<int,int> cnt;
for(int i = 0; i < n; i++){
cin >> x;
cnt[x]++;
}
vector<int> counts;
for(map<int,int>::iterator it = cnt.begin(); it != cnt.end(); it++){
counts.push_back((*it).second);
}
sort(counts.begin(), counts.end());
int ans = 0;
while(counts.size() >= 3){
int len = counts.size();
if(counts[len-3] == 0) break;
ans += counts[len-3];
counts[len-1] -= counts[len-3];
counts[len-2] -= counts[len-3];
counts[len-3] -= counts[len-3];
sort(counts.begin(), counts.end());
}
cout << ans << endl;
}
return 0;
}