結果

問題 No.1909 Detect from Substrings
ユーザー cologne
提出日時 2022-04-22 21:43:41
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 401 ms / 2,000 ms
コード長 674 bytes
コンパイル時間 377 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 13,360 KB
最終ジャッジ日時 2024-06-24 02:50:06
合計ジャッジ時間 11,382 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    N, M = map(int, input().split())
    S = [input() for i in range(N)]

    def subseq(s, x):
        p = 0
        for c in s:
            if p < len(x) and x[p] == c:
                p += 1
        return p == len(x)

    def check(x):
        for s in S:
            if not subseq(x, s):
                return False
        return True

    for i in range(M):
        for j in range(N):
            if S[0][i] != S[j][i]:
                ans = 0
                ans += check(S[0][:i] + S[0][i] + S[j][i:])
                ans += check(S[j][:i] + S[j][i] + S[0][i:])
                print(ans)
                return


if __name__ == '__main__':
    main()
0