結果

問題 No.938 賢人を探せ
ユーザー bal4ubal4u
提出日時 2021-08-12 08:57:31
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 1,276 bytes
コンパイル時間 292 ms
コンパイル使用メモリ 30,464 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-04-08 20:26:23
合計ジャッジ時間 1,111 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 1 ms
6,676 KB
testcase_04 AC 1 ms
6,676 KB
testcase_05 AC 1 ms
6,676 KB
testcase_06 AC 1 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 3 ms
6,676 KB
testcase_09 AC 3 ms
6,676 KB
testcase_10 AC 1 ms
6,676 KB
testcase_11 AC 3 ms
6,676 KB
testcase_12 AC 3 ms
6,676 KB
testcase_13 AC 3 ms
6,676 KB
testcase_14 AC 3 ms
6,676 KB
testcase_15 AC 3 ms
6,676 KB
testcase_16 AC 3 ms
6,676 KB
testcase_17 AC 3 ms
6,676 KB
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 3 ms
6,676 KB
testcase_20 AC 3 ms
6,676 KB
testcase_21 AC 3 ms
6,676 KB
testcase_22 AC 4 ms
6,676 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:12:24: note: in expansion of macro 'gc'
   12 |         int n = 0, c = gc();
      |                        ^~
main.c: In function 'outs':
main.c:9:15: warning: implicit declaration of function 'putchar_unlocked' [-Wimplicit-function-declaration]
    9 | #define pc(c) putchar_unlocked(c)
      |               ^~~~~~~~~~~~~~~~
main.c:23:33: note: in expansion of macro 'pc'
   23 | void outs(char *s) { while (*s) pc(*s++); pc('\n'); }
      |                                 ^~

ソースコード

diff #

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