結果

問題 No.2626 Similar But Different Name
ユーザー ゆにぽけゆにぽけ
提出日時 2024-02-09 22:18:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 173 ms / 3,000 ms
コード長 2,449 bytes
コンパイル時間 2,929 ms
コンパイル使用メモリ 171,764 KB
実行使用メモリ 29,408 KB
最終ジャッジ日時 2024-02-09 22:18:14
合計ジャッジ時間 7,037 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 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 1 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 3 ms
6,676 KB
testcase_11 AC 3 ms
6,676 KB
testcase_12 AC 2 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 2 ms
6,676 KB
testcase_18 AC 167 ms
29,408 KB
testcase_19 AC 31 ms
14,288 KB
testcase_20 AC 25 ms
14,288 KB
testcase_21 AC 24 ms
14,288 KB
testcase_22 AC 168 ms
26,840 KB
testcase_23 AC 171 ms
26,936 KB
testcase_24 AC 168 ms
26,284 KB
testcase_25 AC 167 ms
26,588 KB
testcase_26 AC 167 ms
26,940 KB
testcase_27 AC 173 ms
27,028 KB
testcase_28 AC 167 ms
26,732 KB
testcase_29 AC 166 ms
26,280 KB
testcase_30 AC 167 ms
26,592 KB
testcase_31 AC 167 ms
26,772 KB
testcase_32 AC 168 ms
26,912 KB
testcase_33 AC 173 ms
27,028 KB
testcase_34 AC 166 ms
26,288 KB
testcase_35 AC 167 ms
26,888 KB
testcase_36 AC 165 ms
26,288 KB
testcase_37 AC 164 ms
29,408 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <array>
#include <iterator>
#include <string>
#include <cctype>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cmath>
#include <ctime>
#include <iomanip>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <bitset>
#include <random>
#include <utility>
#include <functional>
#include <atcoder/modint>
#include <atcoder/convolution>
using namespace std;
using mint = atcoder::modint998244353;
using ull = unsigned long long;
const ull mod = (1ULL << 61) - 1;
ull mul(ull a,ull b)
{
	ull au = a >> 31;
	ull ad = a & ((1ULL << 31)-1);
	ull bu = b >> 31;
	ull bd = b & ((1ULL << 31)-1);
	ull mid = au*bd + bu*ad;
	ull midu = mid >> 30;
	ull midd = mid & ((1ULL << 30)-1);

	ull res = au*bu*2 + midu + (midd << 31) + ad*bd;

	res = (res >> 61) + (res & mod);
	if(res >= mod) res -= mod;

	return res;
}
mt19937_64 mt{(unsigned int)time(nullptr)};

void Main()
{
	ull base = mt() % mod;
	int N,M,K;
	cin >> N >> M >> K;
	string S,T;
	cin >> S >> T;
	string s = S,t = T;
	for(char &c : s)
	{
		if('A' <= c && c <= 'Z')
		{
			c -= 'A';
			c += 'a';
		}
	}
	for(char &c : t)
	{
		if('A' <= c && c <= 'Z')
		{
			c -= 'A';
			c += 'a';
		}
	}
	vector<int> match(N - M + 1);
	{
		vector<ull> H(N + 1);
		for(int i = 0;i < N;i++)
		{
			H[i + 1] = mul(H[i],base) + s[i];
		}
		ull h = 0;
		ull p = 1;
		for(int i = 0;i < M;i++)
		{
			p = mul(p,base);
			h = mul(h,base) + t[i];
		}
		for(int i = 0;i + M <= N;i++)
		{
			ull cur = H[i + M] + mod - mul(H[i],p);
			if(cur >= mod)
			{
				cur -= mod;
			}
			if(cur == h)
			{
				match[i] = 1;
			}
		}
	}
	vector<mint> A(N),B(N),C(M),D(M);
	for(int i = 0;i < N;i++)
	{
		if('A' <= S[i] && S[i] <= 'Z')
		{
			A[i] = mint::raw(1);
		}
		else
		{
			B[i] = mint::raw(1);
		}
	}
	for(int i = 0;i < M;i++)
	{
		if('A' <= T[i] && T[i] <= 'Z')
		{
			C[M - i - 1] = mint::raw(1);
		}
		else
		{
			D[M - i - 1] = mint::raw(1);
		}
	}
	vector<mint> P = atcoder::convolution(A,D),Q = atcoder::convolution(B,C);
	int ans = 0;
	for(int i = 0;i + M <= N;i++)
	{
		if(match[i])
		{
			int cur = (int)P[i + M - 1].val() + (int)Q[i + M - 1].val();
			if(1 <= cur && cur <= K)
			{
				ans++;
			}
		}
	}
	cout << ans << "\n";
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int tt = 1;
	/* cin >> tt; */
	while(tt--) Main();
}

0