結果

問題 No.2626 Similar But Different Name
ユーザー umimelumimel
提出日時 2024-02-09 22:33:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 378 ms / 3,000 ms
コード長 1,852 bytes
コンパイル時間 2,982 ms
コンパイル使用メモリ 203,480 KB
実行使用メモリ 56,452 KB
最終ジャッジ日時 2024-02-09 22:33:38
合計ジャッジ時間 10,630 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 1 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 4 ms
6,676 KB
testcase_11 AC 4 ms
6,676 KB
testcase_12 AC 3 ms
6,676 KB
testcase_13 AC 3 ms
6,676 KB
testcase_14 AC 4 ms
6,676 KB
testcase_15 AC 4 ms
6,676 KB
testcase_16 AC 4 ms
6,676 KB
testcase_17 AC 4 ms
6,676 KB
testcase_18 AC 376 ms
56,452 KB
testcase_19 AC 56 ms
25,940 KB
testcase_20 AC 53 ms
25,940 KB
testcase_21 AC 51 ms
25,940 KB
testcase_22 AC 364 ms
44,876 KB
testcase_23 AC 364 ms
45,100 KB
testcase_24 AC 366 ms
42,036 KB
testcase_25 AC 363 ms
43,108 KB
testcase_26 AC 366 ms
45,052 KB
testcase_27 AC 365 ms
45,260 KB
testcase_28 AC 362 ms
43,924 KB
testcase_29 AC 357 ms
41,980 KB
testcase_30 AC 364 ms
43,184 KB
testcase_31 AC 360 ms
44,544 KB
testcase_32 AC 362 ms
45,200 KB
testcase_33 AC 363 ms
45,260 KB
testcase_34 AC 364 ms
42,072 KB
testcase_35 AC 365 ms
44,488 KB
testcase_36 AC 357 ms
42,072 KB
testcase_37 AC 378 ms
56,452 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
#define drep(i, cc, n) for (ll i = (cc); i <= (n); ++i)
#define rep(i, n) drep(i, 0, n - 1)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define fi first
#define se second
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
const ll MOD1000000007 = 1000000007;
const ll MOD998244353 = 998244353;
const ll MOD[3] = {999727999, 1070777777, 1000000007};
const ll LINF = 1LL << 60LL;
const int IINF = (1 << 30) - 1;


vector<int> z_algorithm(string s){
    int n = (int)s.size();
    vector<int> z(n);
    z[0] = n;
    int i=1, j=0;
    while(i < n){
        while(i+j<n && s[j]==s[i+j]) j++;
        z[i] = j;

        if(j == 0){
            i++;
            continue;
        }

        int k=1;
        while(k < j && k+z[k]<j){
            z[i+k] = z[k];
            k++;
        }
        i += k;
        j -= k;
    }

    return z;
}

#include <atcoder/convolution>
using namespace atcoder;

void solve(){
    ll n, m, k; cin >> n >> m >> k;
    string s, t; cin >> s >> t;
    vector<ll> a(n, -1), b(m, -1);
    for(ll i=0; i<n; i++){
        if('A'<=s[i] && s[i]<='Z'){
            s[i] = (char)('a' + (ll)(s[i]-'A'));
            a[i] = 1;
        }
    }
    for(ll i=0; i<m; i++){
        if('A'<=t[i] && t[i]<='Z'){
            t[i] = (char)('a' + (ll)(t[i]-'A'));
            b[i] = 1;
        }
    }

    string r = t+s;
    vector<int> z = z_algorithm(r);

    reverse(all(b));
    vector<ll> c = convolution_ll(a, b);

    ll ans = 0;
    rep(i, n){
        if(z[m+i]<m) continue;
        ll cnt = (m-c[m-1+i])/2;
        if(1<=cnt&&cnt<=k) ans++;
    }
    cout << ans << '\n';
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int T=1;
    //cin >> T;
    while(T--) solve();
}
0