結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー tnakao0123tnakao0123
提出日時 2016-03-20 22:47:00
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 47 ms / 5,000 ms
コード長 1,546 bytes
コンパイル時間 837 ms
コンパイル使用メモリ 87,696 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-04-08 21:08:54
合計ジャッジ時間 1,476 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
6,676 KB
testcase_01 AC 47 ms
6,676 KB
testcase_02 AC 25 ms
6,676 KB
testcase_03 AC 47 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 120.cc: No.120 傾向と対策:門松列(その1) - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100;

/* typedef */

/* global variables */

int ls[MAX_N], cs[MAX_N], ds[MAX_N];

/* subroutines */

/* main */

int main() {
  int tn;
  cin >> tn;

  while (tn--) {
    int n;
    cin >> n;

    for (int i = 0; i < n; i++) cin >> ls[i];
    sort(ls, ls + n);

    int cn = 0, pl = 0, maxc = 0;
    for (int i = 0; i < n; i++) {
      if (pl != ls[i]) cs[cn++] = 1;
      else cs[cn - 1]++;
      pl = ls[i];
      if (maxc < cs[cn - 1]) maxc = cs[cn - 1];
    }
    //for (int i = 0; i < cn; i++) printf("%d ", cs[i]); putchar('\n');

    memset(ds, 0, sizeof(ds));
    for (int i = 0; i < cn; i++) ds[cs[i] - 1]++;
    //for (int i = 0; i < maxc; i++) printf("%d ", ds[i]); putchar('\n');

    int cnt = 0;
    for (;;) {
      while (maxc > 0 && ds[maxc - 1] == 0) maxc--;

      int k = 3, c = maxc - 1, es[3];
      for (int i = 0; i < 3 && c >= 0;) {
	if (ds[c] > 0) {
	  ds[c]--;
	  es[i++] = c;
	}
	else c--;
      }
      if (c < 0) break;

      cnt++;
      for (int i = 0; i < 3; i++)
	if (es[i] > 0) ds[es[i] - 1]++;
    }

    printf("%d\n", cnt);
  }
  return 0;
}
0