結果

問題 No.1005 BOT対策
ユーザー reg7777reg7777
提出日時 2020-03-06 21:53:29
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,554 bytes
コンパイル時間 1,874 ms
コンパイル使用メモリ 171,084 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-22 11:18:26
合計ジャッジ時間 2,595 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 3 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h> 

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define rep(i,N) for(int i=0;i<N;i++)

vector<int> RH(string S,string T){
  int SN=S.size();
  int TN=T.size();
  int_fast64_t b=9973; 
  vector<int_fast64_t>mod={1000000007LL,1000000009LL,1000000021LL}; 
  int M=mod.size();
  vector<int_fast64_t>s(M,0);
  vector<int_fast64_t>t(M,0);
  vector<int_fast64_t>a(M,1);
  for(int i=0;i<TN;i++){
    for(int j=0;j<M;j++){
      a[j]=(a[j]*b)%mod[j];
    }
  }
  for(int i=0;i<TN;i++){
    for(int j=0;j<M;j++){
      s[j]=((s[j]*b)%mod[j]+S[i])%mod[j];
    }
  }
  for(int i=0;i<TN;i++){
    for(int j=0;j<M;j++){
      t[j]=((t[j]*b)%mod[j]+T[i])%mod[j];
    }
  }
  vector<int>res;
  bool ok=true;
  for(int i=0;i<M;i++)if(s[i]!=t[i])ok=false;
  if(ok)res.push_back(0);
  for(int i=0;i+TN<SN;i++){
    ok=true;
    for(int j=0;j<M;j++){
      s[j]=((s[j]*b)%mod[j]-(S[i]*a[j])%mod[j])%mod[j];
      if(s[j]<0)s[j]+=mod[j];
      s[j]=(s[j]+S[i+TN])%mod[j];
      if(s[j]!=t[j])ok=false;
    }
    if(ok)res.push_back(i+1);
  }
  return res;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);

  string S,T;
  cin>>S>>T;
  auto rh=RH(S,T);
  if(T.size()==1&&rh.size()!=0){
    cout<<-1<<endl;
    return 0;
  }
  ll c=0;
  for(int i=0;i<rh.size();i++){
    c++;
    if(i+1<rh.size()){
      if(rh[i]+T.size()-1>rh[i+1])i++;
    }
  }
  cout<<c<<endl;
  return 0;
}
0