結果

問題 No.2626 Similar But Different Name
ユーザー shobonvipshobonvip
提出日時 2024-02-09 22:07:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 195 ms / 3,000 ms
コード長 4,098 bytes
コンパイル時間 4,856 ms
コンパイル使用メモリ 274,024 KB
実行使用メモリ 36,904 KB
最終ジャッジ日時 2024-02-09 22:07:58
合計ジャッジ時間 8,599 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 1 ms
6,676 KB
testcase_05 AC 1 ms
6,676 KB
testcase_06 AC 1 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 2 ms
6,676 KB
testcase_11 AC 3 ms
6,676 KB
testcase_12 AC 3 ms
6,676 KB
testcase_13 AC 3 ms
6,676 KB
testcase_14 AC 3 ms
6,676 KB
testcase_15 AC 3 ms
6,676 KB
testcase_16 AC 3 ms
6,676 KB
testcase_17 AC 3 ms
6,676 KB
testcase_18 AC 194 ms
36,904 KB
testcase_19 AC 120 ms
24,492 KB
testcase_20 AC 96 ms
24,492 KB
testcase_21 AC 98 ms
24,492 KB
testcase_22 AC 167 ms
30,528 KB
testcase_23 AC 170 ms
30,552 KB
testcase_24 AC 160 ms
29,968 KB
testcase_25 AC 173 ms
30,092 KB
testcase_26 AC 189 ms
30,548 KB
testcase_27 AC 187 ms
30,828 KB
testcase_28 AC 168 ms
30,296 KB
testcase_29 AC 165 ms
29,964 KB
testcase_30 AC 165 ms
30,088 KB
testcase_31 AC 192 ms
30,364 KB
testcase_32 AC 165 ms
30,564 KB
testcase_33 AC 169 ms
30,828 KB
testcase_34 AC 168 ms
29,972 KB
testcase_35 AC 170 ms
30,368 KB
testcase_36 AC 195 ms
29,972 KB
testcase_37 AC 172 ms
36,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

//* ATCODER
#include<atcoder/all>
using namespace atcoder;
typedef modint998244353 mint;
//*/

/* BOOST MULTIPRECISION
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
//*/

typedef long long ll;

#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)

template <typename T> bool chmin(T &a, const T &b) {
	if (a <= b) return false;
	a = b;
	return true;
}

template <typename T> bool chmax(T &a, const T &b) {
	if (a >= b) return false;
	a = b;
	return true;
}

template <typename T> T max(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]);
	return ret;
}

template <typename T> T min(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]);
	return ret;
}

template <typename T> T sum(vector<T> &a){
	T ret = 0;
	for (int i=0; i<(int)a.size(); i++) ret += a[i];
	return ret;
}


struct RollingHash {
    using ull = unsigned long long;
    RollingHash(const string& s = "") {
        build(s);
    }
    ull get(int l, int r) {
        assert(0 <= l && l <= r && r <= n);
        return cal(inner_hash[r] + buf - mul(inner_hash[l], pow_base[r - l]));
    }
    static ull get_hash(const string& s) {
        int len = s.size();
        set_hash();
        extend_pow_base(len);
        ull res = 0;
        rep(i, 0, len) res = cal(mul(res, BASE) + s[i]);
        return res;
    }
    static ull concat(const ull& hash1, const ull& hash2, const int& len2) {
        return cal(cal(mul(hash1, pow_base[len2])) + hash2);
    }

  private:
    static constexpr ull MASK30 = (1ULL << 30) - 1;
    static constexpr ull MASK31 = (1ULL << 31) - 1;
    static constexpr ull MASK61 = (1ULL << 61) - 1;
    static constexpr ull MOD = (1ULL << 61) - 1;
    static constexpr ull buf = MOD * 4;
    static ull BASE;
    static vector<ull> pow_base;
    static ull mul(ull a, ull b) {
        ull au = a >> 31, ad = a & MASK31;
        ull bu = b >> 31, bd = b & MASK31;
        ull mid = ad * bu + au * bd;
        ull midu = mid >> 30, midd = mid & MASK30;
        return (au * bu * 2 + midu + (midd << 31) + ad * bd);
    }
    static ull cal(ull x) {
        ull xu = x >> 61;
        ull xd = x & MASK61;
        ull res = xu + xd;
        if (res >= MOD) res -= MOD;
        return res;
    }
    static void set_hash() {
        if (BASE == 0) BASE = (1UL << 31) + (random_device()() & MASK31);
    }
    static void extend_pow_base(int len) {
        int nlen = pow_base.size();
        if (nlen > len) return;
        pow_base.resize(len + 1);
        rep(i, nlen, len + 1) pow_base[i] = cal(mul(pow_base[i - 1], BASE));
    }
    string str;
    int n;
    vector<ull> inner_hash;
    void build(const string& s) {
        set_hash();
        str = s;
        n = s.size();
        extend_pow_base(n);
        inner_hash.resize(n + 1);
        inner_hash[0] = 0;
        rep(i, 0, n) inner_hash[i + 1] = cal(mul(inner_hash[i], BASE) + s[i]);
    }
};

typedef unsigned long long ull;
ull RollingHash::BASE = 0;
vector<ull> RollingHash::pow_base = vector<ull>(1, 1);
using roriha = RollingHash;

int main(){
	int n, m, k; cin >> n >> m >> k;
	string s, t; cin >> s >> t;
	string s_lower = s;
	string t_lower = t;
	vector<mint> s_up(n), s_down(n);
	vector<mint> t_up(m), t_down(n);

	rep(i,0,n){
		if ('A' <= s[i] && s[i] <= 'Z'){
			s_lower[i] = s[i] - 'A' + 'a';
			s_up[i] += 1; 
		}else{
			s_down[i] += 1;
		}
	}

	rep(i,0,m){
		if ('A' <= t[i] && t[i] <= 'Z'){
			t_lower[i] = t[i] - 'A' + 'a';
			t_up[m-1-i] += 1;
		}else{
			t_down[m-1-i] += 1;
		}
	}

	vector<mint> over1 = convolution(s_up, t_down);
	vector<mint> over2 = convolution(s_down, t_up);
	
	roriha rh_s = RollingHash(s_lower);
	roriha rh_t = RollingHash(t_lower);

	int ans = 0;
	rep(i,0,n-m+1){
		mint tmp = over1[m-1+i] + over2[m-1+i];
		if (1 <= tmp.val() && tmp.val() <= k){
			if (rh_s.get(i,i+m) == rh_t.get(0,m)){
				ans+=1;
			}
		}
	}

	cout << ans << '\n';
}

0