結果

問題 No.1005 BOT対策
ユーザー pyraninepyranine
提出日時 2020-12-21 16:11:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 865 bytes
コンパイル時間 1,663 ms
コンパイル使用メモリ 170,348 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 11:43:18
合計ジャッジ時間 2,598 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 2 ms
4,348 KB
testcase_05 WA -
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 2 ms
4,348 KB
testcase_18 WA -
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 2 ms
4,348 KB
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

inline vector<int> z_algorithm(const string &s) {
  int n = (int)s.length();
  vector<int> z(n);
  z[0] = n;
  for (int i = 1, l = 0, r = 0; i < n; i++) {
    if (i <= r) z[i] = min(r - i + 1, z[i - 1]);
    while (i + z[i] < n && s[z[i]] == s[i + z[i]]) z[i]++;
    if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;
  }
  return z;
}

int main() {
  string s, t;
  cin >> s >> t;
  int n = (int)s.size(), m = (int)t.size();
  if (n < m) {
    cout << "0\n";
    return 0;
  }
  if (m == 1) {
    for (int i = 0; i < n; i++) {
      if (s[i] == t[0]) {
        cout << "-1\n";
        return 0;
      }
    }
  }
  auto res = z_algorithm(s+t);
  int cur = 0, ans = 0;
  for (int i = 0; i < res.size(); i++) {
    if (cur <= res[i]) {
      cur = res[i] + m - 1;
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
0