結果

問題 No.120 傾向と対策:門松列(その1)
コンテスト
ユーザー bal4u
提出日時 2019-06-03 10:03:04
言語 C(gnu17)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=gnu17 -Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=incompatible-pointer-types -Wno-error=int-conversion -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 6 ms / 5,000 ms
コード長 1,051 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 349 ms
コンパイル使用メモリ 39,780 KB
最終ジャッジ日時 2026-02-22 03:31:48
ジャッジサーバーID
(参考情報)
judge1 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 4
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

// yukicoder: 120 傾向と対策:門松列(その1)
// 2019.6.3 bal4u

#include <stdio.h>
#include <string.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

// 数値のハッシュ関数
#define HSIZ 1009
typedef struct { int v, f; } HASH;
HASH hash[HSIZ+5], *hashend = hash+HSIZ;
int ma1, ma2;

void insert(int n) {
	HASH *p = hash + n % HSIZ;
	while (p->v) {
		if (p->v == n) {
			if (++(p->f) > ma1) ma1++;
			else if (p->f > ma2) ma2++;
			return;
		}
		if (++p == hashend) p = hash;
	}
	p->v = n, p->f = 1;
	if (p->f > ma1) ma1 = 1;
	else if (p->f > ma2) ma2 = 1;
}

int main()
{
	int i, T, N, ans;

	T = in();
	while (T--) {
		ma1 = ma2 = 0;
		memset(hash, 0, sizeof(hash));
		N = in();
		for (i = 0; i < N; i++) insert(in());
//		printf("ma1=%d, ma2=%d\n", ma1, ma2);
		if (ma1 <= N/3) ans = N/3;
		else if ((N-ma1)/2 >= ma2) ans = (N-ma1)/2;
		else ans = N-ma1-ma2;
		printf("%d\n", ans);
	}
	return 0;
}
0