結果
| 問題 |
No.430 文字列検索
|
| コンテスト | |
| ユーザー |
plasma_e
|
| 提出日時 | 2019-01-20 17:44:40 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 789 bytes |
| コンパイル時間 | 739 ms |
| コンパイル使用メモリ | 93,368 KB |
| 最終ジャッジ日時 | 2025-01-06 20:31:21 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 4 TLE * 10 |
ソースコード
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<set>
#include<map>
#include<string>
int main()
{
std::string str;
std::cin >> str;
auto N = str.size();
int M;
std::cin >> M;
int count = 0;
for (int i = 0; i < M; ++i)
{
std::string C;
std::cin >> C;
std::size_t bhash = 0;
std::size_t mod = 1;
for (auto c : C)
{
bhash *= 26;
bhash += c - 'A';
mod *= 26;
}
std::size_t hash = 0;
for (std::size_t k = 0; k < C.size() - 1; ++k)
{
hash *= 26;
hash += str[k] - 'A';
}
for (std::size_t k = C.size() - 1; k < N; ++k)
{
hash *= 26;
hash += str[k] - 'A';
hash %= mod;
if (hash == bhash)
{
++count;
}
}
}
std::cout << count << std::endl;
}
plasma_e