結果
| 問題 |
No.430 文字列検索
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-05-11 12:30:30 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 274 ms / 2,000 ms |
| コード長 | 3,119 bytes |
| コンパイル時間 | 4,770 ms |
| コンパイル使用メモリ | 316,872 KB |
| 実行使用メモリ | 26,752 KB |
| 最終ジャッジ日時 | 2024-11-10 01:00:33 |
| 合計ジャッジ時間 | 6,227 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 14 |
ソースコード
#if !__INCLUDE_LEVEL__
#include __FILE__
int main()
{
string S;cin >> S;
ll L = S.size();
RH rh(S);
map <ll,ll> hashnum;
range(len,1,11){
range(l,0,L-len+1){
ll hash = rh.get(l,l+len);
hashnum[hash]+=1;
}
}
ll N;cin >> N;
ll Ans = 0;
rep(n,N){
string s;cin >> s;
Ans += hashnum[rh.gethash(s)];
}
cout << Ans << endl;
}
#else
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n; i >= 0; i--)
#define range(i, m, n) for(int i = m; i < n; i++)
#define fore(i,a) for(auto &i:a)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define sum(v) accumulate(all(v),0)
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
const ll INF = 1e16;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll SN(char s){return ll(s-'0');}
ll SN(string s){return stoll(s);}
int alpN(char s){return int(s-'a');}
int AlpN(char s){return int(s-'a');}
using Graph = vector<vector<ll>>;
using mint1 = modint1000000007;
using mint2 = modint998244353;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){for(int i=0;i<(int)v.size();i++)o<<(i>0?" ":"")<<v[i];return o;}//vector空白区切り出力
template< unsigned mod >
struct RollingHash {
vector< unsigned > hashed, power;
inline unsigned mul(unsigned a, unsigned b) const {
unsigned long long x = (unsigned long long) a * b;
unsigned xh = (unsigned) (x >> 32), xl = (unsigned) x, d, m;
asm("divl %4; \n\t" : "=a" (d), "=d" (m) : "d" (xh), "a" (xl), "r" (mod));
return m;
}
RollingHash(const string &s, unsigned base = 10007) {
int sz = (int) s.size();
hashed.assign(sz + 1, 0);
power.assign(sz + 1, 0);
power[0] = 1;
for(int i = 0; i < sz; i++) {
power[i + 1] = mul(power[i], base);
hashed[i + 1] = mul(hashed[i], base) + s[i];
if(hashed[i + 1] >= mod) hashed[i + 1] -= mod;
}
}
unsigned gethash(const string&s, unsigned base = 10007){
int sz = (int) s.size();
unsigned ret = 0;
for(int i = 0; i < sz; i++) {
ret = mul(ret,base)+s[i];
if(ret >= mod)ret-=mod;
}
return ret;
}
unsigned get(int l, int r) const {
unsigned ret = hashed[r] + mod - mul(hashed[l], power[r - l]);
if(ret >= mod) ret -= mod;
return ret;
}
unsigned connect(unsigned h1, int h2, int h2len) const {
unsigned ret = mul(h1, power[h2len]) + h2;
if(ret >= mod) ret -= mod;
return ret;
}
int LCP(const RollingHash< mod > &b, int l1, int r1, int l2, int r2) {
int len = min(r1 - l1, r2 - l2);
int low = -1, high = len + 1;
while(high - low > 1) {
int mid = (low + high) / 2;
if(get(l1, l1 + mid) == b.get(l2, l2 + mid)) low = mid;
else high = mid;
}
return (low);
}
};
using RH = RollingHash< 1000000007 >;
#endif