結果
| 問題 |
No.120 傾向と対策:門松列(その1)
|
| コンテスト | |
| ユーザー |
bal4u
|
| 提出日時 | 2019-06-03 10:03:04 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 7 ms / 5,000 ms |
| コード長 | 1,051 bytes |
| コンパイル時間 | 149 ms |
| コンパイル使用メモリ | 30,080 KB |
| 実行使用メモリ | 6,940 KB |
| 最終ジャッジ日時 | 2024-09-17 20:21:04 |
| 合計ジャッジ時間 | 1,002 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 4 |
コンパイルメッセージ
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();
| ^~
ソースコード
// 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;
}
bal4u