結果

問題 No.2626 Similar But Different Name
ユーザー 沙耶花沙耶花
提出日時 2024-02-09 21:51:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 681 ms / 3,000 ms
コード長 2,649 bytes
コンパイル時間 4,369 ms
コンパイル使用メモリ 266,948 KB
実行使用メモリ 55,488 KB
最終ジャッジ日時 2024-02-09 21:52:00
合計ジャッジ時間 16,447 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 1 ms
6,676 KB
testcase_07 AC 3 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 5 ms
6,676 KB
testcase_11 AC 5 ms
6,676 KB
testcase_12 AC 3 ms
6,676 KB
testcase_13 AC 5 ms
6,676 KB
testcase_14 AC 5 ms
6,676 KB
testcase_15 AC 5 ms
6,676 KB
testcase_16 AC 5 ms
6,676 KB
testcase_17 AC 5 ms
6,676 KB
testcase_18 AC 679 ms
55,488 KB
testcase_19 AC 96 ms
27,588 KB
testcase_20 AC 91 ms
27,588 KB
testcase_21 AC 105 ms
27,588 KB
testcase_22 AC 645 ms
43,044 KB
testcase_23 AC 643 ms
43,232 KB
testcase_24 AC 661 ms
40,080 KB
testcase_25 AC 627 ms
41,196 KB
testcase_26 AC 665 ms
43,224 KB
testcase_27 AC 656 ms
43,552 KB
testcase_28 AC 632 ms
42,004 KB
testcase_29 AC 659 ms
39,936 KB
testcase_30 AC 632 ms
41,168 KB
testcase_31 AC 640 ms
42,688 KB
testcase_32 AC 676 ms
43,396 KB
testcase_33 AC 631 ms
43,552 KB
testcase_34 AC 636 ms
40,096 KB
testcase_35 AC 663 ms
42,700 KB
testcase_36 AC 667 ms
40,096 KB
testcase_37 AC 681 ms
55,488 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 1000000000000000001

struct rolling_hash{

	long long t_hash;
	static inline vector<long long> power;
	static const long long MOD = (1LL<<61)-1;
	static const long long b = 123456;
	int sz;
	
	rolling_hash(){		
		sz = 0;
		t_hash = 0;
	}
	
	rolling_hash(char c){
		sz = 1;
		t_hash = b*c;
	}

	long long mul(__int128 x,__int128 y){
		__int128 t = x*y;
		t = (t>>61) + (t&MOD);
		
		if(t>=MOD)t -= MOD;
		return t;
	}
	
	long long get_pow(int sz){
		if(power.size()>sz)return power[sz];
		
		while(power.size()<=sz){
			if(power.size()==0)power.push_back(1);
			else power.push_back(mul(power.back(),b));
		}
		return power.back();
		
	}
	
	rolling_hash &operator+=(const rolling_hash &another){
		
		(*this).t_hash = mul((*this).t_hash,get_pow(another.sz));
		(*this).t_hash += another.t_hash;
		if((*this).t_hash>=MOD)(*this).t_hash -= MOD;
			
		(*this).sz += another.sz;
		
		return (*this);
	}
	
	rolling_hash operator+(const rolling_hash &another)const{
		return (rolling_hash(*this)+=another);
	}
	
	rolling_hash &operator-=(const rolling_hash &another){

		(*this).t_hash += MOD - mul(another.t_hash,get_pow((*this).sz-another.sz));
		if((*this).t_hash>=MOD)(*this).t_hash -= MOD;
			
		(*this).sz -= another.sz;

		return (*this);
	}
	
	rolling_hash operator-(const rolling_hash &another)const{
		return (rolling_hash(*this)-=another);
	}
	
	bool operator<(const rolling_hash &another)const{
		if((*this).t_hash!=another.t_hash)return (*this).t_hash<another.t_hash;
		return (*this).sz<another.sz;
	}
	
	bool operator==(const rolling_hash &another)const{
		return ((*this).t_hash==another.t_hash && (*this).sz==another.sz);
	}

	
};
int main(){
	
	int N,M,K;
	cin>>N>>M>>K;
	
	string S,T;
	cin>>S>>T;
	
	vector<long long> a(N),b(M);
	rep(i,N){
		if(islower(S[i]))a[i] = 0;
		else a[i] = 1;
	}
	rep(i,M){
		if(isupper(T[i]))b[i] = 0;
		else b[i] = 1;
	}
	
	reverse(b.begin(),b.end());
	auto c = convolution_ll(a,b);
	rep(i,N)a[i]^= 1;
	rep(i,M)b[i] ^= 1;
	
	auto d = convolution_ll(a,b);
	
	vector<rolling_hash> ss(N+1);
	rolling_hash tt;
	rep(i,N){
		if(islower(S[i]))S[i] = toupper(S[i]);
		ss[i+1] = ss[i] + rolling_hash(S[i]);
	}
	rep(i,M){
		if(islower(T[i]))T[i] = toupper(T[i]);
		tt = tt + rolling_hash(T[i]);
	}
	int ans = 0;
	rep(i,N){
		if(i+M>N)break;
		if(!(ss[i+M]-ss[i] == tt))continue;
		int pos = M-1+i;
		long long y = c[pos] + d[pos];
		if(y>=1&&y<=K)ans++;
	}
	cout<<ans<<endl;
	
	return 0;
}
0