結果

問題 No.1909 Detect from Substrings
ユーザー siganaisiganai
提出日時 2022-04-22 23:05:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 407 ms / 2,000 ms
コード長 2,206 bytes
コンパイル時間 479 ms
コンパイル使用メモリ 86,936 KB
実行使用メモリ 174,000 KB
最終ジャッジ日時 2023-09-06 09:49:53
合計ジャッジ時間 12,984 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 144 ms
78,788 KB
testcase_01 AC 142 ms
78,580 KB
testcase_02 AC 144 ms
78,756 KB
testcase_03 AC 173 ms
79,580 KB
testcase_04 AC 145 ms
79,788 KB
testcase_05 AC 153 ms
79,780 KB
testcase_06 AC 156 ms
81,212 KB
testcase_07 AC 154 ms
81,320 KB
testcase_08 AC 392 ms
173,408 KB
testcase_09 AC 295 ms
155,304 KB
testcase_10 AC 194 ms
97,436 KB
testcase_11 AC 207 ms
95,208 KB
testcase_12 AC 184 ms
91,088 KB
testcase_13 AC 294 ms
152,020 KB
testcase_14 AC 328 ms
156,868 KB
testcase_15 AC 358 ms
166,792 KB
testcase_16 AC 182 ms
89,476 KB
testcase_17 AC 162 ms
81,840 KB
testcase_18 AC 164 ms
81,568 KB
testcase_19 AC 165 ms
81,304 KB
testcase_20 AC 162 ms
81,184 KB
testcase_21 AC 363 ms
162,712 KB
testcase_22 AC 407 ms
173,400 KB
testcase_23 AC 193 ms
98,536 KB
testcase_24 AC 191 ms
102,600 KB
testcase_25 AC 189 ms
91,056 KB
testcase_26 AC 375 ms
159,388 KB
testcase_27 AC 392 ms
173,524 KB
testcase_28 AC 334 ms
155,728 KB
testcase_29 AC 360 ms
174,000 KB
testcase_30 AC 382 ms
173,532 KB
testcase_31 AC 330 ms
166,156 KB
testcase_32 AC 386 ms
173,472 KB
testcase_33 AC 315 ms
153,788 KB
testcase_34 AC 394 ms
173,388 KB
testcase_35 AC 343 ms
168,152 KB
testcase_36 AC 390 ms
173,468 KB
testcase_37 AC 345 ms
168,272 KB
testcase_38 AC 392 ms
173,468 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env PyPy3

from collections import Counter, defaultdict, deque
import itertools
import re
import math
from functools import reduce
import operator
import bisect
import heapq
import functools
mod=10**9+7

import sys
input=sys.stdin.readline

n,m=map(int,input().split())
s=[input().rstrip() for _ in range(n)]
ansl = []
ansl2 = []
if n > 2:
    for j in range(m):
        l = [0] * 26
        for i in range(n):
            l[ord(s[i][j])-ord('a')] += 1
        if max(l) == n:
            for k in range(26):
                if l[k] == n:
                    ansl.append(chr(k+ord('a')))
        elif max(l) == n - 1:
            for k in range(26):
                if l[k] == n - 1:
                    ansl.append(chr(k+ord('a')))
                if l[k] == 1:
                    pos = k
            for ii in range(n):
                if ord(s[ii][j])-ord('a') == pos:
                    for jj in range(j,m):
                        ansl.append(s[ii][jj])
                    break
            break
        else:
            print(0)
            exit()
    for i in range(n):
        now = 0
        for aa in ansl:
            if now < m and aa == s[i][now]:
                now += 1
        if now < m:
            print(0)
            exit()
    print(1)
else:
    for j in range(m):
        l = [0] * 26
        for i in range(n):
            l[ord(s[i][j])-ord('a')] += 1
        if max(l) == n:
            for k in range(26):
                if l[k] == n:
                    ansl.append(chr(k+ord('a')))
                    ansl2.append(chr(k+ord('a')))
        else:
            ansl.append(s[1][j])
            ansl2.append(s[0][j])
            for jj in range(j,m):
                ansl.append(s[0][jj])
                ansl2.append(s[1][jj])
            break
    c = 0
    for i in range(n):
        now = 0
        for aa in ansl:
            if now < m and aa == s[i][now]:
                now += 1
        if now != m:
            break
    else:
        c += 1
    for i in range(n):
        now = 0
        for aa in ansl2:
            if now < m and aa == s[i][now]:
                now += 1
        if now != m:
            break
    else:
        c += 1
    print(c)
0