結果
問題 |
No.1005 BOT対策
|
ユーザー |
![]() |
提出日時 | 2025-04-15 20:48:56 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,575 bytes |
コンパイル時間 | 475 ms |
コンパイル使用メモリ | 82,392 KB |
実行使用メモリ | 72,944 KB |
最終ジャッジ日時 | 2025-04-15 20:49:23 |
合計ジャッジ時間 | 2,953 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 WA * 8 |
ソースコード
def compute_failure(t): n = len(t) fail = [0] * n j = 0 for i in range(1, n): while j > 0 and t[i] != t[j]: j = fail[j-1] if t[i] == t[j]: j += 1 fail[i] = j else: fail[i] = 0 return fail def main(): import sys s = sys.stdin.readline().strip() t = sys.stdin.readline().strip() m = len(t) n = len(s) if m == 0: print(0) return if m > n: print(0) return failure = compute_failure(t) INF = float('inf') # Initialize DP table dp = [[INF] * (m + 1) for _ in range(n + 1)] dp[0][0] = 0 for i in range(n): for j in range(m + 1): if dp[i][j] == INF: continue # Option 1: Insert a '.' after current character if dp[i+1][0] > dp[i][j] + 1: dp[i+1][0] = dp[i][j] + 1 # Option 2: Do not insert, process current character current_j = j c = s[i] while current_j > 0 and c != t[current_j]: current_j = failure[current_j - 1] if c == t[current_j]: current_j += 1 else: current_j = 0 if current_j < m: if dp[i+1][current_j] > dp[i][j]: dp[i+1][current_j] = dp[i][j] min_ans = min(dp[n][:m]) if min_ans == INF: print(-1) else: print(min_ans) if __name__ == "__main__": main()