結果

問題 No.938 賢人を探せ
ユーザー bal4ubal4u
提出日時 2019-12-05 19:37:41
言語 C
(gcc 12.3.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,464 bytes
コンパイル時間 951 ms
コンパイル使用メモリ 29,620 KB
実行使用メモリ 11,240 KB
最終ジャッジ日時 2023-08-21 03:35:47
合計ジャッジ時間 7,555 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

int getchar_unlocked(void);
#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 { char *s; int id; } HASH;
HASH hash[HASHSIZ+2], *hashend = hash + HASHSIZ;

int insert(char *s, int id) {
	unsigned long long i;
	int j;
	char *p;
	HASH *tp;

	i = 0, p = s;
	for (j = 0; *p && j < 12; j++) i = (i << 5) + (*p++ +1-'a');
	tp = hash + (int)(i % HASHSIZ);
	while (tp->s != NULL) {
		if (!strcmp(tp->s, s)) return tp->id;
		if (++tp == hashend) tp = hash;
	}
	tp->s = s, tp->id = id;
	return -1;
}

int lookup(char *s) {
	unsigned long long i;
	int j;
	char *p;
	HASH *tp;

	i = 0, p = s;
	for (j = 0; *p && j < 12; j++) i = (i << 5) + (*p++ +1-'a');
	tp = hash + (int)(i % HASHSIZ);
	while (tp->s != NULL) {
		if (!strcmp(tp->s, s)) return 1;
		if (++tp == hashend) tp = 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;
}
0