結果
| 問題 | No.430 文字列検索 |
| コンテスト | |
| ユーザー |
plasma_e
|
| 提出日時 | 2019-01-20 17:53:46 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 172 ms / 2,000 ms |
| コード長 | 732 bytes |
| 記録 | |
| コンパイル時間 | 926 ms |
| コンパイル使用メモリ | 99,288 KB |
| 最終ジャッジ日時 | 2025-01-06 20:31:26 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 14 |
ソースコード
#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;
std::map<std::size_t, int>hash_count;
for (std::size_t i = 0; i < N; ++i)
{
std::size_t hash = 0;
for (std::size_t k = 0; i + k < N&&k < 10; ++k)
{
hash *= 27;
hash += str[i + k] - 'A' + 1;
++hash_count[hash];
}
}
for (int i = 0; i < M; ++i)
{
std::string C;
std::cin >> C;
std::size_t hash = 0;
for (auto c : C)
{
hash *= 27;
hash += c - 'A' + 1;
}
count += hash_count[hash];
}
std::cout << count << std::endl;
}
plasma_e