結果

問題 No.430 文字列検索
ユーザー h_nosonh_noson
提出日時 2017-07-19 14:40:52
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,657 ms / 2,000 ms
コード長 1,106 bytes
コンパイル時間 930 ms
コンパイル使用メモリ 93,804 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-17 04:01:34
合計ジャッジ時間 12,581 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 774 ms
6,944 KB
testcase_02 AC 665 ms
6,944 KB
testcase_03 AC 424 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 5 ms
6,940 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 4 ms
6,940 KB
testcase_11 AC 1,655 ms
6,940 KB
testcase_12 AC 1,645 ms
6,944 KB
testcase_13 AC 1,657 ms
6,940 KB
testcase_14 AC 1,585 ms
6,940 KB
testcase_15 AC 1,385 ms
6,944 KB
testcase_16 AC 728 ms
6,940 KB
testcase_17 AC 678 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cassert>
using namespace std;

#define GET_ARG(a,b,c,F,...) F
#define REP3(i,s,e) for (i = s; i <= e; i++)
#define REP2(i,n) REP3 (i,0,(int)(n)-1)
#define REP(...) GET_ARG (__VA_ARGS__,REP3,REP2) (__VA_ARGS__)
#define RREP3(i,s,e) for (i = s; i >= e; i--)
#define RREP2(i,n) RREP3 (i,(int)(n)-1,0)
#define RREP(...) GET_ARG (__VA_ARGS__,RREP3,RREP2) (__VA_ARGS__)
#define DEBUG(x) cerr << #x ": " << x << endl

int a[11];

int main(void) {
    int i, j, k, m;
    string s;
    cin >> s >> m;
    int ans = 0;
    REP (k,m) {
        string t;
        cin >> t;
        a[0] = -1;
        for (i = 1, j = 0; i < t.size(); a[++i] = ++j) {
            while (j >= 0 && t[i] != t[j]) j = a[j];
        }
        for (i = 0, j = 0; i < s.size(); i++) {
            while (j >= 0 && s[i] != t[j]) j = a[j];
            j++;
            if (j == t.size()) {
                ans++;
                j = a[j];
            }
        }
    }
    cout << ans << endl;
    return 0;
}
0