結果
| 問題 | No.430 文字列検索 |
| コンテスト | |
| ユーザー |
kurenai3110
|
| 提出日時 | 2016-10-03 00:36:54 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 808 bytes |
| 記録 | |
| コンパイル時間 | 811 ms |
| コンパイル使用メモリ | 77,420 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-10 00:07:22 |
| 合計ジャッジ時間 | 17,555 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 11 TLE * 3 |
ソースコード
#include <iostream>
#include <string>
#include <iomanip>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
int ans;
int bm(string s, string t,int index)
{
int n = s.size();
int m = t.size();
map<char, int> f;
for (int i = 0; i<m; i++) f[t[i]] = m - 1 - i;
int p = m - 1+index;
while (p<n)
{
int k = m - 1;
while (k >= 0 && t[k] == s[p]) { k--; p--; }
if (k == -1) {
ans++;
return p + 1;
}
else
{
if (f.find(s[p]) == f.end()) p += m;
else p += max(f[s[p]], m - k);
}
}
return -1;
}
int main()
{
string s;
cin >> s;
int m; cin >> m;
for (int i = 0; i < m; i++) {
string target; cin >> target;
int index = 0;
while (1) {
index = bm(s, target, index);
if (index == -1)break;
index++;
}
}
cout << ans << endl;
return 0;
}
kurenai3110