結果
| 問題 |
No.938 賢人を探せ
|
| コンテスト | |
| ユーザー |
bal4u
|
| 提出日時 | 2021-08-12 08:49:11 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 7 ms / 2,000 ms |
| コード長 | 1,249 bytes |
| コンパイル時間 | 335 ms |
| コンパイル使用メモリ | 30,464 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-01 11:18:46 |
| 合計ジャッジ時間 | 1,210 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 21 |
コンパイルメッセージ
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:11:24: note: in expansion of macro 'gc'
11 | int n = 0, c = gc();
| ^~
ソースコード
// yuki 938 賢人を探せ
// 2019.12.5 bal4u
#include <stdio.h>
#include <string.h>
typedef long long ll;
#define gc() getchar_unlocked()
int in() { // 非負整数の入力
int n = 0, c = gc();
do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
return n;
}
void ins(char *s) { // 文字列の入力 スペース以下の文字で入力終了
do *s = gc();
while (*s++ > ' ');
*(s-1) = 0;
}
// 文字列のハッシュ関数
#define HASHSIZ 199999
typedef struct { ll s; int id; } HASH;
HASH hash[HASHSIZ+5], *hashend = hash+HASHSIZ;
void insert(char *s, int id) {
ll j = 0; while (*s) j = (j << 6) + (*s++ - 0x40);
HASH *p = hash + (int)(j % HASHSIZ);
while (p->s) {
if (p->s == j) return;
if (++p == hashend) p = hash;
}
p->s = j, p->id = id;
}
int lookup(char *s) {
ll j = 0; while (*s) j = (j << 6) + (*s++ - 0x40);
HASH *p = hash + (int)(j % HASHSIZ);
while (p->s) {
if (p->s == j) return 1;
if (++p == hashend) p = hash;
}
return 0;
}
int w;
char A[20005][12], B[20005][12];
int main()
{
int i, n, N;
N = in();
for (i = 0; i < N; ++i) {
ins(A[i]), insert(A[i], i);
ins(B[i]);
}
n = N; for (i = 0; i < N; ++i) {
if (!lookup(B[i])) {
puts(B[i]);
insert(B[i], n++);
}
}
return 0;
}
bal4u