結果
| 問題 | No.1909 Detect from Substrings | 
| コンテスト | |
| ユーザー |  Moss_Local | 
| 提出日時 | 2022-04-22 21:25:27 | 
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) | 
| 結果 | 
                                MLE
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,198 bytes | 
| コンパイル時間 | 198 ms | 
| コンパイル使用メモリ | 12,800 KB | 
| 実行使用メモリ | 818,792 KB | 
| 最終ジャッジ日時 | 2024-06-24 02:27:11 | 
| 合計ジャッジ時間 | 3,266 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 5 MLE * 1 -- * 30 | 
ソースコード
from collections import defaultdict
from functools import lru_cache
from sys import flags, stdin
import math
import re
import queue
import typing
import itertools
import bisect
import statistics
# import numpy as np
# from numpy.core.function_base import _needs_add_docstring
# from numpy.core.numeric import outer
input = stdin.readline
MOD = 1000000007
INF = 122337203685477580
# longest common subsequence
def lcs(a, b):
    dp = [[0]*(len(b)+1) for _ in range(len(a)+1)]
    for i in range(1, len(a)+1):
        for j in range(1, len(b)+1):
            if a[i-1] == b[j-1]:
                dp[i][j] = dp[i-1][j-1] + 1
            else:
                dp[i][j] = max(dp[i-1][j], dp[i][j-1])
    # print(a, b, dp[-1][-1])
    # print(dp)
    return dp[-1][-1]
def solve():
    n, m = map(int, input().split())
    if n > 2:
        print(0)
        return
    a = input()
    b = input()
    l = lcs(a[0:-1], b[0:-1])
    l1 = lcs(a[1:-1], b)
    l2 = lcs(a[0:-2], b)
    # print(l)
    # print(l1)
    # print(l2)
    if l == l1 and l == l2 and l == m-1:
        print(2)
    elif l == m-1:
        print(1)
    else:
        print(0)
    return
if __name__ == '__main__':
    solve()
            
            
            
        