結果

問題 No.2626 Similar But Different Name
ユーザー Nzt3Nzt3
提出日時 2024-02-09 23:44:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,568 bytes
コンパイル時間 2,392 ms
コンパイル使用メモリ 206,516 KB
実行使用メモリ 13,480 KB
最終ジャッジ日時 2024-02-09 23:44:54
合計ジャッジ時間 8,195 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 3 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 3 ms
6,676 KB
testcase_05 AC 3 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 178 ms
6,676 KB
testcase_08 AC 177 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 103 ms
6,676 KB
testcase_11 AC 104 ms
6,676 KB
testcase_12 AC 115 ms
6,676 KB
testcase_13 AC 102 ms
6,676 KB
testcase_14 AC 50 ms
6,676 KB
testcase_15 AC 56 ms
6,676 KB
testcase_16 AC 46 ms
6,676 KB
testcase_17 AC 47 ms
6,676 KB
testcase_18 AC 12 ms
6,676 KB
testcase_19 TLE -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

constexpr array<ll,2> primes={1029268439,1236788731};
constexpr int base=340522599;
constexpr int MAX_N=500000;

void ch_hash_add(array<ll,2>& a,char c){
  a[0]=(a[0]*base+c)%primes[0];
  a[1]=(a[1]*base+c)%primes[1];
}
void ch_hash_rem(array<ll,2>& a,char c,const array<ll,2>& inv){
  a[0]=((a[0]-inv[0]*c)%primes[0]+primes[0])%primes[0];
  a[1]=((a[1]-inv[1]*c)%primes[1]+primes[1])%primes[1];
}
namespace Lib{
  ll modpow(ll a,int n,ll mod){
    long long ret=1,t=a;
    while(n>0){
      if(n&1)ret=ret*t%mod;
      t=t*t%mod;
      n/=2;
    }
    return ret;
  }
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N,M,K;
  cin>>N>>M>>K;
  string S,T;
  cin>>S>>T;
  array<ll,2>T_hash={0,0},inv={Lib::modpow(base,M,primes[0]),Lib::modpow(base,M,primes[1])};
  for(int i=0;i<M;i++){
    char c=T[i];
    if(c>='a'){
      c^=32;
    }
    ch_hash_add(T_hash,c);
  }
  array<ll,2>S_hash={0,0};
  for(int i=0;i<M;i++){
    char c=S[i];
    if(c>='a'){
      c^=32;
    }
    ch_hash_add(S_hash,c);
  }
  S+='/';
  bitset<MAX_N>Sb,Tb,Ab;
  for(int i=0;i<N;i++){
    if(S[i]>='a')Sb[i]=1;
  }
  for(int i=0;i<M;i++){
    if(T[i]>='a')Tb[i]=1;
    Ab[i]=1;
  }
  int ans=0;
  for(int i=M;i<=N;i++){
    if(T_hash==S_hash){
      int s=(((Sb>>(i-M))&Ab)^Tb).count();
      if(s>0&&s<=K)ans+=1;
    }
    char c=S[i];
    if(c>='a'){
      c^=32;
    }
    ch_hash_add(S_hash,c);
    c=S[i-M];
    if(c>='a'){
      c^=32;
    }
    ch_hash_rem(S_hash,c,inv);
  }
  cout<<ans<<'\n';
}
0