結果

問題 No.52 よくある文字列の問題
ユーザー bal4ubal4u
提出日時 2019-05-07 17:53:01
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 885 bytes
コンパイル時間 1,121 ms
コンパイル使用メモリ 28,420 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-14 16:27:26
合計ジャッジ時間 1,459 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 0 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// yukicoder: No.52 よくある文字列の問題
// 2019.5.7 bal4u

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

#define gc() getchar()
int ins(char *s)
{
	char *p = s;
	do *s = gc();
	while (*s++ > ' ');
	*--s = 0;
	return s - p;
}

#define HASHSIZ 150011
typedef struct { char s[12]; } HASH;
HASH hash[HASHSIZ+2], *hashend = hash + HASHSIZ;

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

	i = 0, p = s; while (*p) i = (i<<5) + *p++;
	tp = hash + (int)(i % HASHSIZ);
	while (tp->s[0]) {
		if (!strcmp(tp->s, s)) return 0;
		if (++tp == hashend) tp = hash;
	}
	strcpy(tp->s, s);
	return 1;
}

char s[12]; int w;
char t[12];
int ans;

void rec(int l, int r, int sz)
{
	if (sz == w) {
		ans += insert(t);
		return;
	}
	t[sz] = s[l];
	rec(l+1, r, sz+1);
	t[sz] = s[r];
	rec(l, r-1, sz+1);
}

int main()
{
	w = ins(s);
	rec(0, w-1, 0);
	printf("%d\n", ans);
	return 0;
}
0