結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー koba-e964koba-e964
提出日時 2015-06-18 21:05:05
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 65 ms / 5,000 ms
コード長 1,218 bytes
コンパイル時間 838 ms
コンパイル使用メモリ 99,744 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-21 09:31:19
合計ジャッジ時間 1,955 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
4,376 KB
testcase_01 AC 64 ms
4,376 KB
testcase_02 AC 30 ms
4,380 KB
testcase_03 AC 65 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef pair<int, int> PI;
const double EPS=1e-9;



int main(void){
  int t;
  cin >> t;
  REP(loop_var, 0, t) {
    int n;
    cin >> n;
    map<int, int> m;
    REP(i, 0, n) {
      int l;
      cin >> l;
      if (m.count(l) == 0) {
	m[l] = 0;
      }
      ++m[l];
    }
    vector<int> v;
    for (map<int, int>::iterator it = m.begin(); it != m.end(); ++it) {
      v.push_back(it->second);
    }
    int cnt = 0;
    while (1) {
      sort(v.begin(), v.end());
      reverse(v.begin(), v.end());
      if (v.size() >= 3 && v[0] >= 1 && v[1] >= 1 && v[2] >= 1) {
	v[0]--;
	v[1]--;
	v[2]--;
	cnt++;
	continue;
      }
      break;
    }
    cout << cnt << endl;
  }
}
0