結果

問題 No.2626 Similar But Different Name
ユーザー Taiki0715Taiki0715
提出日時 2024-02-09 22:22:45
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 212 ms / 3,000 ms
コード長 4,698 bytes
コンパイル時間 3,586 ms
コンパイル使用メモリ 182,328 KB
実行使用メモリ 40,692 KB
最終ジャッジ日時 2024-02-09 22:22:54
合計ジャッジ時間 8,191 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 ms
6,676 KB
testcase_04 AC 1 ms
6,676 KB
testcase_05 AC 1 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 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 3 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 2 ms
6,676 KB
testcase_18 AC 193 ms
40,692 KB
testcase_19 AC 37 ms
23,848 KB
testcase_20 AC 34 ms
23,848 KB
testcase_21 AC 36 ms
23,848 KB
testcase_22 AC 187 ms
35,116 KB
testcase_23 AC 211 ms
35,148 KB
testcase_24 AC 187 ms
33,732 KB
testcase_25 AC 189 ms
34,300 KB
testcase_26 AC 189 ms
35,136 KB
testcase_27 AC 191 ms
35,300 KB
testcase_28 AC 191 ms
34,628 KB
testcase_29 AC 208 ms
33,724 KB
testcase_30 AC 189 ms
34,292 KB
testcase_31 AC 189 ms
34,960 KB
testcase_32 AC 192 ms
35,288 KB
testcase_33 AC 194 ms
35,300 KB
testcase_34 AC 189 ms
33,744 KB
testcase_35 AC 212 ms
34,964 KB
testcase_36 AC 189 ms
33,744 KB
testcase_37 AC 192 ms
40,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
template<int mod>istream &operator>>(istream &is,static_modint<mod> &a){long long b;is>>b;a=b;return is;}
istream &operator>>(istream &is,modint &a){long long b;cin>>b;a=b;return is;}
#endif
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) static_cast<void>(0)
#define debugg(...) static_cast<void>(0)
template<typename T1,typename T2>ostream &operator<<(ostream &os,const pair<T1,T2>&p){os<<p.first<<' '<<p.second;return os;}
#endif
using ll=long long;
using ull=unsigned long long;
using P=pair<ll,ll>;
template<typename T>using minque=priority_queue<T,vector<T>,greater<T>>;
template<typename T>bool chmax(T &a,const T &b){return (a<b?(a=b,true):false);}
template<typename T>bool chmin(T &a,const T &b){return (a>b?(a=b,true):false);}
template<typename T1,typename T2>istream &operator>>(istream &is,pair<T1,T2>&p){is>>p.first>>p.second;return is;}
template<typename T>istream &operator>>(istream &is,vector<T> &a){for(auto &i:a)is>>i;return is;}
template<typename T1,typename T2>void operator++(pair<T1,T2>&a,int n){a.first++,a.second++;}
template<typename T1,typename T2>void operator--(pair<T1,T2>&a,int n){a.first--,a.second--;}
template<typename T>void operator++(vector<T>&a,int n){for(auto &i:a)i++;}
template<typename T>void operator--(vector<T>&a,int n){for(auto &i:a)i--;}
#define reps(i,a,n) for(int i=(a);i<(n);i++)
#define rep(i,n) reps(i,0,n)
#define all(x) x.begin(),x.end()
#define pcnt(x) __builtin_popcountll(x)
ll myceil(ll a,ll b){return (a+b-1)/b;}
template<typename T,size_t n,size_t id=0>
auto vec(const int (&d)[n],const T &init=T()){
  if constexpr (id<n)return vector(d[id],vec<T,n,id+1>(d,init));
  else return init;
}
void SOLVE();
int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  #ifdef LOCAL
  clock_t start=clock();
  #endif
  int testcase=1;
  //cin>>testcase;
  for(int i=0;i<testcase;i++){
    SOLVE();
  }
  #ifdef LOCAL
  cerr<<"time:";
  cerr<<(clock()-start)/1000;
  cerr<<"ms\n";
  #endif
}
namespace RollingHashInfo{
  constexpr ull MOD=(1ull<<61)-1;
  constexpr ull MASK31=(1ull<<31)-1;
  constexpr ull MASK30=(1ull<<30)-1;
  ull mul(ull a,ull b){
    ull au=a>>31;
    ull ad=a&MASK31;
    ull bu=b>>31;
    ull bd=b&MASK31;
    ull mid=au*bd+ad*bu;
    ull midu=mid>>30;
    ull midd=mid&MASK30;
    return (au*bu*2+midu+(midd<<31)+ad*bd)%MOD;
  }
  ull pow61(ull a,ull p){
    ull ret=1;
    while(p){
      if(p&1)ret=mul(ret,a);
      a=mul(a,a);
      p>>=1;
    }
    return ret;
  }
  constexpr ull MAX=100;
  static ull primitive_root(){
    random_device rng;
    ull k=rng();
    while(true){
      if(gcd(k,MOD-1)!=1){
        ull now=pow61(37,k);
        if(now>MAX)return now;
      }
      k=rng();
    }
    return 0;
  }
  static ull base=primitive_root();
  vector<ull>power{1};
  void build(int n){
    if(power.size()>=n+1)return;
    int pre=power.size();
    power.resize(n+1);
    for(int i=pre;i<=n;i++)power[i]=mul(power[i-1],base);
  }
  ull connect(ull l,ull r,int len){
    l=mul(l,power[len]);
    l+=r;
    if(l>=MOD)l-=MOD;
    return l;
  }
}
struct RollingHash{
  vector<ull>sum;
  RollingHash(const string &s){
    int n=s.size();
    sum.resize(n+1,0);
    RollingHashInfo::build(n);
    rep(i,n){
      sum[i+1]=RollingHashInfo::mul(sum[i],RollingHashInfo::base)+s[i];
      if(sum[i+1]>=RollingHashInfo::MOD)sum[i+1]-=RollingHashInfo::MOD;
    }
  }
  ull get(int l,int r)const{
    ull left=RollingHashInfo::mul(sum[l],RollingHashInfo::power[r-l]);
    ull right=sum[r];
    if(right>=left)return right-left;
    return right+RollingHashInfo::MOD-left;
  }
};
namespace RollingHashInfo{
  int lcp(const RollingHash &rh1,int l1,int r1,const RollingHash &rh2,int l2,int r2){
    int len=min(r1-l1,r2-l2);
    int low=0,high=len+1;
    while(high-low>1){
      int mid=(low+high)/2;
      if(rh1.get(l1,l1+mid)==rh2.get(l2,l2+mid))low=mid;
      else high=mid;
    }
    return low;
  }
}
void SOLVE(){
  int n,m,k;
  cin>>n>>m>>k;
  string s,t;
  cin>>s>>t;
  string s2=s,t2=t;
  rep(i,n)if(s2[i]>='a')s2[i]^=32;
  rep(i,m)if(t2[i]>='a')t2[i]^=32;
  RollingHash rs(s2),rt(t2);
  vector<bool>same(n-m+1,false);
  ull hsrt=rt.get(0,m);
  rep(i,n-m+1)same[i]=rs.get(i,i+m)==hsrt;
  vector<int>a(n),b(m);
  rep(i,n)a[i]=s[i]>='a';
  rep(i,m)b[i]=t[i]>='a';
  vector<int>cnt(n-m+1,0);
  reverse(all(b));
  rep(i,m)b[i]^=1;
  auto c=convolution(a,b);
  reps(i,m-1,n)cnt[i-(m-1)]+=c[i];
  rep(i,m)b[i]^=1;
  rep(i,n)a[i]^=1;
  auto d=convolution(a,b);
  reps(i,m-1,n)cnt[i-(m-1)]+=d[i];
  int ans=0;
  rep(i,n-m+1)if(same[i]&&1<=cnt[i]&&cnt[i]<=k)ans++;
  cout<<ans<<endl;
}
0