結果
問題 | No.120 傾向と対策:門松列(その1) |
ユーザー | knewknowl |
提出日時 | 2015-02-10 23:41:52 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 27 ms / 5,000 ms |
コード長 | 720 bytes |
コンパイル時間 | 582 ms |
コンパイル使用メモリ | 73,012 KB |
実行使用メモリ | 4,384 KB |
最終ジャッジ日時 | 2023-09-05 23:05:59 |
合計ジャッジ時間 | 1,306 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 22 ms
4,376 KB |
testcase_01 | AC | 26 ms
4,380 KB |
testcase_02 | AC | 13 ms
4,376 KB |
testcase_03 | AC | 27 ms
4,384 KB |
ソースコード
#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; }