結果

問題 No.938 賢人を探せ
コンテスト
ユーザー bal4u
提出日時 2021-08-12 08:57:31
言語 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  
実行時間 8 ms / 2,000 ms
コード長 1,276 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 237 ms
コンパイル使用メモリ 39,528 KB
最終ジャッジ日時 2026-02-22 07:49:08
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

// yuki 938 賢人を探せ
// 2019.12.5 bal4u

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

typedef long long ll;
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)

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;
}

void outs(char *s) { while (*s) pc(*s++); pc('\n'); }

// 文字列のハッシュ関数
#define HASHSIZ 199999
typedef ll HASH;
ll hash[HASHSIZ+5], *hashend = hash+HASHSIZ;

void insert(char *s) {
	ll j = 0; while (*s) j = (j << 6) + (*s++ - 0x40);
	HASH *p = hash + (int)(j % HASHSIZ);
	while (*p) {
		if (*p == j) return;
		if (++p == hashend) p = hash;
	}
	*p = j;
}

int lookup(char *s) {
	ll j = 0; while (*s) j = (j << 6) + (*s++ - 0x40);
	HASH *p = hash + (int)(j % HASHSIZ);
	while (*p) {
		if (*p == 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]);
		ins(B[i]);
	}
	n = N; for (i = 0; i < N; ++i) {
		if (!lookup(B[i])) {
			outs(B[i]);
			insert(B[i]);
		}
	}
	return 0;
}
0