結果
| 問題 |
No.430 文字列検索
|
| コンテスト | |
| ユーザー |
akakimidori
|
| 提出日時 | 2019-08-13 15:34:23 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 7 ms / 2,000 ms |
| コード長 | 1,026 bytes |
| コンパイル時間 | 195 ms |
| コンパイル使用メモリ | 30,080 KB |
| 実行使用メモリ | 6,144 KB |
| 最終ジャッジ日時 | 2024-11-10 00:28:13 |
| 合計ジャッジ時間 | 774 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 14 |
ソースコード
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>
#include<string.h>
typedef int32_t i32;
#define ALLOC(size,type) ((type*)calloc((size),sizeof(type)))
typedef struct node {
i32 cnt;
struct node *next[26];
} node;
node *NODE_ARRAY = NULL;
node* add(node *t, char *s) {
if (t == NULL) {
t = NODE_ARRAY++;
}
if (*s == '\0') {
t->cnt++;
} else {
i32 k = *s - 'A';
t->next[k] = add (t->next[k], s + 1);
}
return t;
}
void run (void) {
char *s = ALLOC (50000 + 1, char);
scanf ("%s", s);
i32 m;
scanf ("%" SCNi32, &m);
NODE_ARRAY = ALLOC(m * 10 + 1, node);
node *r = NULL;
while (m--) {
char c[11];
scanf ("%s", c);
r = add (r, c);
}
i32 n = strlen (s);
i32 ans = 0;
for (i32 i = 0; i < n; ++i) {
node *p = r;
for (i32 j = 0; j < 10 && j < n - i; ++j) {
p = p->next[s[i + j] - 'A'];
if (p == NULL) break;
ans += p->cnt;
}
}
printf ("%" PRIi32 "\n", ans);
}
int main (void) {
run();
return 0;
}
akakimidori