結果
| 問題 |
No.430 文字列検索
|
| ユーザー |
|
| 提出日時 | 2020-02-27 02:31:33 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,169 bytes |
| コンパイル時間 | 663 ms |
| コンパイル使用メモリ | 83,324 KB |
| 実行使用メモリ | 26,496 KB |
| 最終ジャッジ日時 | 2024-11-10 00:41:12 |
| 合計ジャッジ時間 | 3,537 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 4 |
| other | WA * 14 |
ソースコード
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <map>
using namespace std;
// Aに0を割り当てるとAAAとかでおかしくなるので、1を割り当てる
const int N_CHAR = 27;
string S;
map<long long, int> hashes;
long long calc_hash(string t) {
long long x = 0;
for (char c: t) {
x = x * N_CHAR + (c - 'A' + 1);
}
return x;
}
void make_hashes(int len) {
printf("---make_hashes: len %d\n", len);
if (len > S.size()) {
return;
}
long long mod = 1;
for (int i = 0; i < len; i++) {
mod *= N_CHAR;
}
auto t = S.substr(0, len);
cout << t << endl;
auto x = calc_hash(t);
hashes[x]++;
printf("hash find: %15lld\n", x);
for (int i = t.size(); i < S.size(); i++) {
x = x * N_CHAR % mod + (S[i] - 'A' + 1);
printf("hash find: %15lld\n", x);
hashes[x]++;
}
}
int main() {
string c;
cin >> S;
for (int i = 1; i <= 10; i++) {
make_hashes(i);
}
int ans = 0;
int m;
cin >> m;
for (int i = 0; i < m; i++) {
cin >> c;
auto x = calc_hash(c);
ans += hashes[x];
printf("c %10s: hash %15lld, add %3d\n", c.c_str(), x, hashes[x]);
}
cout << ans << endl;
}