結果
| 問題 |
No.1005 BOT対策
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-08-07 22:27:58 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,151 bytes |
| コンパイル時間 | 1,890 ms |
| コンパイル使用メモリ | 169,824 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-08-07 22:28:01 |
| 合計ジャッジ時間 | 3,190 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 WA * 6 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
const int64_t inf = 1e18;
/*
#include<atcoder/string>
// const int64_t mod = 998244353;
// const int64_t mod = 1000000007;
*/
vector<int> z_algorithm(string s) {
vector<int> res(int(s.size()));
res[0] = (int) s.size();
int j = 0;
for (int i = 1; i < (int)s.size();) {
while (i + j < (int)s.size() && s[j] == s[i+j]) j++;
res[i] = j;
if (j == 0) {i++; continue;}
int k = 1;
while (i + k < (int) s.size() && k + res[k] < j) res[i+k] = res[k], k++;
i += k, j -= k;
}
return res;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
string s, t;
cin >> s >> t;
vector<int> z = z_algorithm(t + s);
int n = t.size();
int ans = 0;
if (t.size() == 1) {
bool flag = false;
for (char c: s) {
if (c == t[0]) cout << -1 << endl;
}
cout << 0 << endl;
return 0;
}
for (int i = n; i < z.size();) {
if (z[i] >= n) {
ans++;
i += n-1;
} else {
i++;
}
}
cout << ans << endl;
}