結果

問題 No.1005 BOT対策
ユーザー ht06359ht06359
提出日時 2024-08-07 22:24:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,015 bytes
コンパイル時間 1,838 ms
コンパイル使用メモリ 169,948 KB
実行使用メモリ 13,884 KB
最終ジャッジ日時 2024-08-07 22:24:37
合計ジャッジ時間 5,456 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,884 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 TLE -
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 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
const int64_t inf = 1e18;
/*
#include<atcoder/string>
// const int64_t mod = 998244353;
// const int64_t mod = 1000000007;
*/


vector<int> z_algorithm(string s) {
    vector<int> res(int(s.size()));
    res[0] = (int) s.size();
    int j = 0;
    for (int i = 1; i < (int)s.size();) {
        while (i + j < (int)s.size() && s[j] == s[i+j]) j++;
        res[i] = j;
        if (j == 0) {i++; continue;}
        int k = 1;
        while (i + k < (int) s.size() && k + res[k] < j) res[i+k] = res[k], k++;
        i += k, j -= k;
    }
    return res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    string s, t;
    cin >> s >> t;
    vector<int> z = z_algorithm(t + s);
    int n = t.size();
    int cnt = 0;
    int ans = 0;
    for (int i = n; i < z.size();) {
        if (z[i] >= n) {
            ans++;
            i += n-1;
        } else {
            i++;
        }
    }
    if (t.size() == 1) ans = -1;
    cout << ans << endl;
}
0