結果

問題 No.430 文字列検索
ユーザー h_nosonh_noson
提出日時 2017-07-25 23:29:41
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,619 bytes
コンパイル時間 825 ms
コンパイル使用メモリ 95,388 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-17 23:40:00
合計ジャッジ時間 9,261 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 432 ms
5,376 KB
testcase_02 AC 260 ms
5,376 KB
testcase_03 AC 255 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 4 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 327 ms
5,376 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 z[10], a[10];

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