結果

問題 No.2626 Similar But Different Name
ユーザー MagentorMagentor
提出日時 2024-01-04 22:48:37
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 892 ms / 3,000 ms
コード長 3,493 bytes
コンパイル時間 5,531 ms
コンパイル使用メモリ 316,328 KB
実行使用メモリ 58,920 KB
最終ジャッジ日時 2024-01-04 22:49:00
合計ジャッジ時間 22,256 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 3 ms
6,676 KB
testcase_08 AC 3 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 6 ms
6,676 KB
testcase_11 AC 6 ms
6,676 KB
testcase_12 AC 4 ms
6,676 KB
testcase_13 AC 5 ms
6,676 KB
testcase_14 AC 6 ms
6,676 KB
testcase_15 AC 6 ms
6,676 KB
testcase_16 AC 6 ms
6,676 KB
testcase_17 AC 6 ms
6,676 KB
testcase_18 AC 730 ms
58,920 KB
testcase_19 AC 345 ms
53,348 KB
testcase_20 AC 315 ms
53,348 KB
testcase_21 AC 97 ms
27,840 KB
testcase_22 AC 874 ms
58,036 KB
testcase_23 AC 859 ms
58,096 KB
testcase_24 AC 892 ms
57,880 KB
testcase_25 AC 886 ms
57,968 KB
testcase_26 AC 853 ms
58,084 KB
testcase_27 AC 854 ms
58,160 KB
testcase_28 AC 887 ms
58,016 KB
testcase_29 AC 830 ms
49,552 KB
testcase_30 AC 802 ms
50,300 KB
testcase_31 AC 824 ms
51,132 KB
testcase_32 AC 827 ms
51,616 KB
testcase_33 AC 799 ms
51,652 KB
testcase_34 AC 828 ms
49,568 KB
testcase_35 AC 825 ms
51,144 KB
testcase_36 AC 803 ms
49,568 KB
testcase_37 AC 757 ms
58,920 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
template<typename T> inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); }
template<typename T> inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); }
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep2(i, m ,n) for (int i = (m); i < (long long)(n); i++)
#define REP(i, n) for (long long i = 1; i < (long long)(n); i++)
typedef long long ll;
#define updiv(N,X) (N + X - 1) / X
#define l(n) n.begin(),n.end()
#define YesNo(Q) Q==1?cout<<"Yes":cout<<"No"
using P = pair<int, int>;
using mint = modint;
const int MOD = 998244353LL;
const ll INF = 999999999999LL;
vector<long long> fact, fact_inv, inv;
/*  init_nCk :二項係数のための前処理
    計算量:O(n)
*/
template <typename T>
void input(vector<T> &v){
 rep(i,v.size()){cin>>v[i];}
  return;
}
void init_nCk(int SIZE) {
    fact.resize(SIZE + 5);
    fact_inv.resize(SIZE + 5);
    inv.resize(SIZE + 5);
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < SIZE + 5; i++) {
        fact[i] = fact[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % MOD;
    }
}
/*  nCk :MODでの二項係数を求める(前処理 int_nCk が必要)
    計算量:O(1)
*/
long long nCk(int n, int k) {
    assert(!(n < k));
    assert(!(n < 0 || k < 0));
    return fact[n] * (fact_inv[k] * fact_inv[n - k] % MOD) % MOD;
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

ll POW(ll a,ll n){
  long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a;
        a = a * a;
        n >>= 1;
    }
    return res;
}
class KMP
{
public:
    string pattern;
    int plen;
    vector<int> table;
    KMP(const string s) : pattern(s), plen((int)pattern.size()), table(plen+1){
        table[0] = -1;
        int j = -1;
        for(int i = 0; i < plen; i++){
            while(j >= 0 && pattern[i] != pattern[j]) j = table[j];
            if(pattern[i+1] == pattern[++j]) table[i+1] = table[j];
            else table[i+1] = j;
        }
    }
    void search(const string& text, vector<int>& res){
        int head = 0, j = 0, tlen = (int)text.size();
        while(head + j < tlen){
            if(pattern[j] == text[head + j]){
                if(++j != plen) continue;
                res.push_back(head);
            }
            head += j - table[j], j = max(table[j], 0);
        }
    }
};

int main() {
 int n,m,k;cin>>n>>m>>k;
 string s,t;cin>>s>>t;auto s1 = s;auto t1 = t;
 rep(i,n){s1[i]=tolower(s[i]);}
 rep(i,m){t1[i]=tolower(t[i]);}
 KMP kmp(t1);
 vector<int> res;
 kmp.search(s1,res);
 set<ll> st;
 rep(i,res.size()){st.insert(res[i]);}
 vector<ll> a(n,0);vector<ll> b(m,0);
 rep(i,n){if(islower(s[i])){a[i]++;}}
 rep(i,m){if(isupper(t[t.size()-1-i])){b[i]++;}}
 auto u = convolution_ll(a,b);
 rep(i,n){a[i] = 1-a[i];}
 rep(i,m){b[i] = 1-b[i];}
 auto v = convolution_ll(a,b);
 //t.size()-1
 //rep(i,a.size()){cout<<a[i]<<" ";}cout<<endl;
 ll cnt = 0;
 rep(i,n){
 //	cout << (int)(st.count(i)) << " " << u[i+t.size()-1]+v[i+t.size()-1] << endl;
 	if(st.count(i)&&0<u[i+t.size()-1]+v[i+t.size()-1]&&u[i+t.size()-1]+v[i+t.size()-1]<=k){cnt++;}
 }
 cout << cnt << endl;return 0;
}
0