結果
| 問題 |
No.52 よくある文字列の問題
|
| コンテスト | |
| ユーザー |
bal4u
|
| 提出日時 | 2019-05-07 18:02:46 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 5,000 ms |
| コード長 | 793 bytes |
| コンパイル時間 | 132 ms |
| コンパイル使用メモリ | 30,080 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-01 23:34:38 |
| 合計ジャッジ時間 | 682 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 11 |
ソースコード
// 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 5003
long long hash[HASHSIZ+2], *hashend = hash+HASHSIZ;
int insert(char *s)
{
long long i, *tp;
i = 0; while (*s) i = (i<<5) + *s++;
tp = hash + (int)(i % HASHSIZ);
while (*tp) {
if (*tp == i) return 0;
if (++tp == hashend) tp = hash;
}
*tp = i;
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;
}
bal4u