結果
| 問題 | No.1909 Detect from Substrings | 
| コンテスト | |
| ユーザー |  Moss_Local | 
| 提出日時 | 2022-04-22 21:28:42 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                TLE
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,221 bytes | 
| コンパイル時間 | 329 ms | 
| コンパイル使用メモリ | 82,828 KB | 
| 実行使用メモリ | 102,004 KB | 
| 最終ジャッジ日時 | 2024-06-24 02:32:53 | 
| 合計ジャッジ時間 | 5,965 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 5 TLE * 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(2)]
    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 % 2][j] = dp[(i-1) % 2][j-1] + 1
            else:
                dp[i % 2][j] = max(dp[(i-1) % 2][j], dp[i % 2][j-1])
    # print(a, b, dp[-1][-1])
    # print(dp)
    return dp[len(a)%2][-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()
            
            
            
        