結果
| 問題 | No.120 傾向と対策:門松列(その1) | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2016-11-27 16:44:36 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 56 ms / 5,000 ms | 
| コード長 | 881 bytes | 
| コンパイル時間 | 1,823 ms | 
| コンパイル使用メモリ | 182,132 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-11-27 12:13:35 | 
| 合計ジャッジ時間 | 2,682 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 4 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
signed main(){
  int T; cin >> T;
  for( int kase = 0; kase < T; ++kase ){
    int N; cin >> N;
    vector< int > L( N );
    for( int i = 0; i < N; ++i )
      cin >> L[ i ];
    priority_queue< pair< int, int > > pq;
    map< int, int > lcnt;
    for( int i = 0; i < N; ++i )
      ++lcnt[ L[ i ] ];
    for( auto it = lcnt.begin(); it != lcnt.end(); ++it )
      pq.emplace( it->second, it->first );
    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 > 0 )
        pq.emplace( a.first - 1, a.second );
      if( b.first - 1 > 0 )
        pq.emplace( b.first - 1, b.second );
      if( c.first - 1 > 0 )
        pq.emplace( c.first - 1, c.second );
    }
    cout << ans << endl;
  }
  return 0;
}
            
            
            
        