結果

問題 No.2626 Similar But Different Name
ユーザー AngrySadEightAngrySadEight
提出日時 2024-01-02 17:38:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 391 ms / 3,000 ms
コード長 1,164 bytes
コンパイル時間 1,919 ms
コンパイル使用メモリ 108,720 KB
実行使用メモリ 55,532 KB
最終ジャッジ日時 2024-01-02 17:38:52
合計ジャッジ時間 10,511 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 2 ms
6,548 KB
testcase_04 AC 2 ms
6,548 KB
testcase_05 AC 2 ms
6,548 KB
testcase_06 AC 4 ms
6,548 KB
testcase_07 AC 2 ms
6,548 KB
testcase_08 AC 2 ms
6,548 KB
testcase_09 AC 3 ms
6,548 KB
testcase_10 AC 6 ms
6,548 KB
testcase_11 AC 4 ms
6,548 KB
testcase_12 AC 3 ms
6,548 KB
testcase_13 AC 4 ms
6,548 KB
testcase_14 AC 3 ms
6,548 KB
testcase_15 AC 4 ms
6,548 KB
testcase_16 AC 4 ms
6,548 KB
testcase_17 AC 4 ms
6,548 KB
testcase_18 AC 373 ms
55,532 KB
testcase_19 AC 61 ms
27,352 KB
testcase_20 AC 56 ms
27,352 KB
testcase_21 AC 56 ms
27,352 KB
testcase_22 AC 391 ms
45,172 KB
testcase_23 AC 356 ms
45,348 KB
testcase_24 AC 353 ms
42,708 KB
testcase_25 AC 382 ms
43,680 KB
testcase_26 AC 354 ms
45,304 KB
testcase_27 AC 362 ms
45,560 KB
testcase_28 AC 370 ms
44,320 KB
testcase_29 AC 360 ms
42,656 KB
testcase_30 AC 359 ms
43,636 KB
testcase_31 AC 361 ms
44,796 KB
testcase_32 AC 375 ms
45,412 KB
testcase_33 AC 365 ms
45,560 KB
testcase_34 AC 352 ms
42,612 KB
testcase_35 AC 386 ms
44,860 KB
testcase_36 AC 355 ms
42,612 KB
testcase_37 AC 374 ms
55,532 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/convolution>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using namespace atcoder;
using ll = long long;

ll conv_ch(char c) {
    ll ret;
    if (c >= 'A' && c <= 'Z') {
        ret = ((ll)(c - 'A') + 1) * 10000 + 1;
    } else {
        ret = ((ll)(c - 'a') + 1) * 10000;
    }
    return ret;
}

int main() {
    ll N, M, K;
    cin >> N >> M >> K;
    string S;
    string T;
    cin >> S;
    cin >> T;
    vector<ll> sq_sum_s(N + 1, 0);
    ll sq_sum_t = 0;
    vector<ll> val_s(N, 0);
    vector<ll> val_t(M, 0);
    for (ll i = 0; i < N; i++) {
        ll val = conv_ch(S[i]);
        sq_sum_s[i + 1] = sq_sum_s[i] + val * val;
        val_s[i] = val;
    }
    for (ll i = 0; i < M; i++) {
        ll val = conv_ch(T[M - 1 - i]);
        sq_sum_t += val * val;
        val_t[i] = val;
    }
    vector<ll> conv_st = convolution_ll(val_s, val_t);
    ll ans = 0;
    for (ll i = M - 1; i <= N - 1; i++) {
        ll diffs =
            (sq_sum_s[i + 1] - sq_sum_s[i + 1 - M]) + sq_sum_t - 2 * conv_st[i];
        if (diffs >= 1 && diffs <= K) {
            ans++;
        }
    }
    cout << ans << endl;
}
0