結果

問題 No.1909 Detect from Substrings
ユーザー Moss_LocalMoss_Local
提出日時 2022-04-22 21:25:27
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
MLE  
実行時間 -
コード長 1,198 bytes
コンパイル時間 150 ms
コンパイル使用メモリ 10,900 KB
実行使用メモリ 817,052 KB
最終ジャッジ日時 2023-09-06 07:41:46
合計ジャッジ時間 3,892 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
11,204 KB
testcase_01 AC 41 ms
11,196 KB
testcase_02 AC 41 ms
11,204 KB
testcase_03 AC 41 ms
11,500 KB
testcase_04 AC 42 ms
11,324 KB
testcase_05 AC 41 ms
11,420 KB
testcase_06 AC 42 ms
11,208 KB
testcase_07 AC 41 ms
11,280 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