結果
問題 | No.1005 BOT対策 |
ユーザー |
|
提出日時 | 2022-07-27 10:56:20 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,230 bytes |
コンパイル時間 | 101 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 10,752 KB |
最終ジャッジ日時 | 2024-07-16 17:16:59 |
合計ジャッジ時間 | 1,731 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 WA * 1 |
other | AC * 18 WA * 9 |
ソースコード
import sysfrom collections import OrderedDictS = input()T = input()if len(T) == 1 and S == T:print(-1)sys.exit()if len(T) == 1 and S.count(T) == 0:print(S.count(T))sys.exit()# cnt = S.count(T)# if len(T) == 1 and cnt == 0:# print(cnt)# elif len(T) == 1 and cnt != 0:# print(-1)# else:# print(cnt)# Z-algorithm# https://qiita.com/masayoshi361/items/1be110f13412f5431da2# https://perogram.hateblo.jp/entry/z_algo_revisit# https://qiita.com/Pro_ktmr/items/16904c9570aa0953bf05def Z_algo(S):n = len(S)LCP = [0]*ni = 1j = 0c = 0 # 最も末尾側までLCPを求めたインデックスfor i in range(1, n):# i番目からのLCPが以前計算したcからのLCPに含まれている場合if i+LCP[i-c] < c+LCP[c]:LCP[i] = LCP[i-c]else:j = max(0, c+LCP[c]-i)while i+j < n and S[j] == S[i+j]:j += 1LCP[i] = jc = iLCP[0] = nreturn LCP# min_T = "".join(OrderedDict.fromkeys(T))# print(min_T)# print(Z_algo(S))z_results = Z_algo(T+S)# print(z_results)results = [x for x in z_results[len(T):] if x >= len(T)]print(len(results))