結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー bal4ubal4u
提出日時 2019-06-03 10:03:04
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 1,051 bytes
コンパイル時間 183 ms
コンパイル使用メモリ 30,572 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 23:13:54
合計ジャッジ時間 948 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
4,348 KB
testcase_01 AC 7 ms
4,348 KB
testcase_02 AC 4 ms
4,348 KB
testcase_03 AC 6 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function 'in':
main.c:8:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration]
    8 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:14:24: note: in expansion of macro 'gc'
   14 |         int n = 0, c = gc();
      |                        ^~

ソースコード

diff #

// 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