結果

問題 No.1909 Detect from Substrings
ユーザー Moss_LocalMoss_Local
提出日時 2022-04-22 21:26:13
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 1,198 bytes
コンパイル時間 970 ms
コンパイル使用メモリ 87,048 KB
実行使用メモリ 843,652 KB
最終ジャッジ日時 2023-09-06 07:42:51
合計ジャッジ時間 6,582 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 314 ms
99,440 KB
testcase_01 AC 308 ms
99,796 KB
testcase_02 AC 308 ms
99,692 KB
testcase_03 AC 304 ms
99,672 KB
testcase_04 AC 303 ms
99,828 KB
testcase_05 AC 311 ms
99,804 KB
testcase_06 AC 308 ms
99,456 KB
testcase_07 AC 305 ms
99,596 KB
testcase_08 MLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
権限があれば一括ダウンロードができます

ソースコード

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