結果
問題 | No.1909 Detect from Substrings |
ユーザー |
![]() |
提出日時 | 2023-06-12 12:17:16 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 146 ms / 2,000 ms |
コード長 | 663 bytes |
コンパイル時間 | 186 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 155,924 KB |
最終ジャッジ日時 | 2024-06-11 14:55:38 |
合計ジャッジ時間 | 6,810 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 36 |
ソースコード
def produce(x, y): K = len(x) left, right = 0, K-1 while x[left] == y[left]: left += 1 while x[right] == y[right]: right -= 1 temp1 = x[:left] + [y[left]] + x[left:] temp2 = x[:right+1] + [y[right]]+ x[right+1:] return [temp1, temp2] def match(x, y): now = 0 temp = y + ["$"] for xx in x: if temp[now] == xx: now += 1 return now == len(temp) - 1 N, M = map(int, input().split()) S = [] for i in range(N): S.append(list(input())) kouho = produce(S[0], S[1]) ans = [1, 1] for i in range(1, N): for j in range(2): ans[j] &= match(kouho[j], S[i]) print(sum(ans))