結果

問題 No.430 文字列検索
ユーザー face4face4
提出日時 2018-09-26 12:03:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 853 bytes
コンパイル時間 445 ms
コンパイル使用メモリ 66,540 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-04-18 02:39:57
合計ジャッジ時間 3,840 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
10,624 KB
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
using namespace std;

typedef long long ll;

int main(){
    ll times[10] = {};
    times[0] = 1;
    for(int i = 1; i < 10; i++){
        times[i] = times[i-1]*26;
    }

    string s;
    cin >> s;

    int n = s.length();

    int m;
    cin >> m;

    string c;
    int ans = 0;
    for(int i = 0; i < m; i++){
        cin >> c;
        int clen = c.length();
        if(clen > n)  continue;
        ll target = 0, roll = 0;
        for(int j = 0; j < clen; j++){
            target = target*26 + (c[j]-'A');
            roll = roll * 26 + s[j]-'A';
        }
        
        if(roll == target)  ans++;

        for(int j = clen; j < n; j++){
            roll %= times[clen-1];
            roll *= 26;
            roll += s[j]-'A';
            if(roll == target)  ans++;
        }
    }

    cout << ans << endl;

    return 0;
}
0