結果
| 問題 | No.430 文字列検索 | 
| コンテスト | |
| ユーザー |  moyashi_senpai | 
| 提出日時 | 2016-10-03 00:22:16 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 1,777 ms / 2,000 ms | 
| コード長 | 1,488 bytes | 
| コンパイル時間 | 1,249 ms | 
| コンパイル使用メモリ | 87,436 KB | 
| 実行使用メモリ | 6,272 KB | 
| 最終ジャッジ日時 | 2024-11-10 00:07:02 | 
| 合計ジャッジ時間 | 13,735 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 14 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:72:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   72 |         scanf("%s", str);
      |         ~~~~~^~~~~~~~~~~
main.cpp:73:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   73 |         scanf("%d", &m);
      |         ~~~~~^~~~~~~~~~
main.cpp:77:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   77 |                 scanf("%s", pat);
      |                 ~~~~~^~~~~~~~~~~
            
            ソースコード
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <bitset>
#include <stack>
#include <cstdlib>
#include <complex>
#include <unordered_map>
#define REP(i,n) for(int i = 0; n > i; i++)
#define MODU 33
#define Range(x,a,b) ((a) <= (x) && (x) <= (b))
#define POWT(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define C_D(c) ((c) - '0')
#define D_C(d) ((d) + '0')
using namespace std;
typedef vector<int> Ivec;
typedef pair<int, int> pii;
typedef long long int ll;
#include <cstdio>
void kmp_maketable(const char *key, int *table)
{
	table[0] = -1; table[1] = 0;
	int i = 2, j = 0;
	while (i == 0 || key[i - 1]) {
		if (key[i - 1] == key[j]) {
			table[i++] = ++j;
		}
		else if (j>0) {
			j = table[j];
		}
		else {
			table[i++] = 0;
		}
	}
}
int kmp_search(const char *str, const char *key, const int *table)
{
	int cou = 0;
	int i = 0, j = 0;
	while (str[i]) {
		if (str[i] == key[j]) {
			if (!key[j + 1]) {
				cou++;
			}
			i++, ++j;
		}
		else if (j>0) {
			j = table[j];
		}
		else {
			i++;
		}
	}
	return cou;
}
int main() {
	char str [500001];
	int m;
	scanf("%s", str);
	scanf("%d", &m);
	ll cou = 0;
	REP(i, m) {
		char pat[101];
		scanf("%s", pat);
		int table[500001];
		kmp_maketable(pat,table);
		cou += kmp_search(str,pat,table);
	}
	printf("%lld\n",cou);
	return 0;
}
            
            
            
        