結果
問題 |
No.1005 BOT対策
|
ユーザー |
|
提出日時 | 2020-03-07 01:29:58 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 702 bytes |
コンパイル時間 | 1,426 ms |
コンパイル使用メモリ | 166,088 KB |
実行使用メモリ | 7,844 KB |
最終ジャッジ日時 | 2025-06-20 00:49:52 |
合計ジャッジ時間 | 2,438 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 29 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); string s, t; cin >> s >> t; int n = s.size(), m = t.size(); vector<int> match(n, false); for (int i = 0; i <= n - m; ++i) { match[i] = (s.substr(i, m) == t); } constexpr int INF = 1e9; vector<int> dp(n + 1, INF); dp[0] = 0; for (int i = 1; i <= n; ++i) { for (int j = i - 1; j >= 0; --j) { if (i - j >= m && match[j]) break; if (dp[j] >= INF) continue; dp[i] = min(dp[i], dp[j] + (j > 0)); } } cout << (dp[n] >= INF ? -1 : dp[n]) << endl; return 0; }