結果
| 問題 | No.120 傾向と対策:門松列(その1) | 
| コンテスト | |
| ユーザー |  tottoripaper | 
| 提出日時 | 2015-03-05 21:42:02 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 22 ms / 5,000 ms | 
| コード長 | 834 bytes | 
| コンパイル時間 | 574 ms | 
| コンパイル使用メモリ | 58,704 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-06-24 08:19:40 | 
| 合計ジャッジ時間 | 1,043 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 4 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:10:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   10 |     scanf("%d", &T);
      |     ~~~~~^~~~~~~~~~
main.cpp:17:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   17 |         scanf("%d", &N);
      |         ~~~~~^~~~~~~~~~
main.cpp:21:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   21 |             scanf("%d", &l);
      |             ~~~~~^~~~~~~~~~
            
            ソースコード
#include <cstdio>
#include <queue>
#include <unordered_map>
std::priority_queue<int> q;
std::unordered_map<int,int> m;
int main(){
    int T;
    scanf("%d", &T);
    while(T--){
        while(!q.empty()){q.pop();}
        m.clear();
        
        int N;
        scanf("%d", &N);
        
        for(int i=0;i<N;i++){
            int l;
            scanf("%d", &l);
            m[l]++;
        }
        for(const auto& p : m){
            q.push(p.second);
        }
        int res = 0;
        while(q.size() >= 3){
            res++;
            
            int xs[3];
            for(int i=0;i<3;i++){
                xs[i] = q.top();
                q.pop();
            }
            for(int i=0;i<3;i++){
                if(xs[i] > 1){q.push(xs[i]-1);}
            }
        }
        printf("%d\n", res);
    }
}
            
            
            
        