結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー hogeover30hogeover30
提出日時 2015-01-29 17:58:11
言語 C++11
(gcc 11.4.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 557 bytes
コンパイル時間 419 ms
コンパイル使用メモリ 61,012 KB
最終ジャッジ日時 2023-09-05 07:38:16
合計ジャッジ時間 884 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:14:9: error: ‘vector’ was not declared in this scope
         vector<int> v;
         ^~~~~~
main.cpp:14:9: note: ‘std::vector’ is defined in header ‘<vector>’; did you forget to ‘#include <vector>’?
main.cpp:4:1:
+#include <vector>
 using namespace std;
main.cpp:14:9:
         vector<int> v;
         ^~~~~~
main.cpp:14:16: error: expected primary-expression before ‘int’
         vector<int> v;
                ^~~
main.cpp:15:25: error: ‘v’ was not declared in this scope
         for(auto& x: a) v.push_back(x.second);
                         ^
main.cpp:16:14: error: ‘v’ was not declared in this scope
         sort(v.rbegin(), v.rend());
              ^

ソースコード

diff #

#include <iostream>
#include <map>
#include <algorithm>
using namespace std;
int main()
{
    int T; cin>>T;
    while (T--) {
        int n; cin>>n;
        map<int, int> a;
        while (n--) {
            int l; cin>>l; a[l]++;
        }
        vector<int> v;
        for(auto& x: a) v.push_back(x.second);
        sort(v.rbegin(), v.rend());

        int res=0, m=v.size();
        while (m>2) {
            ++res;
            for(int i=0;i<3;++i) if (--v[i]==0) --m;
            sort(v.rbegin(), v.rend());
        }
        cout<<res<<endl;
    }
}
0