結果
| 問題 |
No.120 傾向と対策:門松列(その1)
|
| コンテスト | |
| ユーザー |
knewknowl
|
| 提出日時 | 2015-02-10 23:41:52 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 27 ms / 5,000 ms |
| コード長 | 720 bytes |
| コンパイル時間 | 758 ms |
| コンパイル使用メモリ | 61,176 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-23 18:25:48 |
| 合計ジャッジ時間 | 1,317 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 4 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:9:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
9 | scanf("%d",&t);
| ~~~~~^~~~~~~~~
main.cpp:13:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
13 | scanf("%d",&n);
| ~~~~~^~~~~~~~~
main.cpp:15:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
15 | int l;scanf("%d",&l);
| ~~~~~^~~~~~~~~
ソースコード
#include <cstdio>
#include <algorithm>
#include <map>
#include <vector>
#include <queue>
using namespace std;
int main(){
int t;
scanf("%d",&t);
while(t--){
int n;
map<int,int> tbl;
scanf("%d",&n);
for(int i=0;i<n;++i){
int l;scanf("%d",&l);
tbl[l]++;
}
priority_queue<int> Q;
for(map<int,int>::iterator it=tbl.begin();it!=tbl.end();++it){
Q.push((*it).second);
}
int ans = 0;
while(true){
if(Q.size()<3) break;
int a = Q.top(); Q.pop();
int b = Q.top(); Q.pop();
int 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);
}
printf("%d\n",ans);
}
return 0;
}
knewknowl