結果

問題 No.1909 Detect from Substrings
ユーザー Moss_Local
提出日時 2022-04-22 21:26:13
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 1,198 bytes
コンパイル時間 211 ms
コンパイル使用メモリ 82,496 KB
実行使用メモリ 849,360 KB
最終ジャッジ日時 2024-06-24 02:28:12
合計ジャッジ時間 4,174 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 5 MLE * 1 -- * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

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()
0