結果

問題 No.1909 Detect from Substrings
ユーザー ygd.ygd.
提出日時 2022-04-22 22:32:12
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 2,305 bytes
コンパイル時間 510 ms
コンパイル使用メモリ 87,064 KB
実行使用メモリ 263,596 KB
最終ジャッジ日時 2023-09-06 09:09:02
合計ジャッジ時間 60,175 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
71,452 KB
testcase_01 AC 78 ms
71,400 KB
testcase_02 AC 75 ms
71,640 KB
testcase_03 AC 88 ms
75,912 KB
testcase_04 AC 94 ms
76,448 KB
testcase_05 AC 121 ms
77,280 KB
testcase_06 AC 149 ms
77,168 KB
testcase_07 AC 151 ms
77,332 KB
testcase_08 TLE -
testcase_09 TLE -
testcase_10 AC 1,199 ms
258,372 KB
testcase_11 AC 1,195 ms
258,460 KB
testcase_12 AC 674 ms
175,832 KB
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 TLE -
testcase_22 TLE -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 TLE -
testcase_27 TLE -
testcase_28 TLE -
testcase_29 TLE -
testcase_30 TLE -
testcase_31 TLE -
testcase_32 TLE -
testcase_33 TLE -
testcase_34 TLE -
testcase_35 TLE -
testcase_36 TLE -
testcase_37 TLE -
testcase_38 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
#input = sys.stdin.readline
#input = sys.stdin.buffer.readline #文字列はダメ
#sys.setrecursionlimit(1000000)
#import bisect
#import itertools
#import random
#from heapq import heapify, heappop, heappush
#from collections import defaultdict 
#from collections import deque
#import copy
#import math
#from functools import lru_cache
#@lru_cache(maxsize=None)
#MOD = pow(10,9) + 7
#MOD = 998244353
#dx = [1,0,-1,0]
#dy = [0,1,0,-1]
#dx8 = [1,1,0,-1,-1,-1,0,1]
#dy8 = [0,1,1,1,0,-1,-1,-1]

class RollingHash():
    def __init__(self, s, base, mod):
        self.mod = mod
        self.pw = pw = [1]*(len(s)+1)
 
        l = len(s)
        self.h = h = [0]*(l+1)
 
        v = 0
        for i in range(l):
            h[i+1] = v = (v * base + ord(s[i])) % mod #文字ではなく数字のリストの場合はord不要
        v = 1
        for i in range(l):
            pw[i+1] = v = v * base % mod
    def get(self, l, r): #S[l:r)indexでいうl文字目からr-1文字目
        return (self.h[r] - self.h[l] * self.pw[r-l]) % self.mod

base1 = 1007; base2 = 2009
mod1 = 1000000007; mod2 = 1000000009

def main():
    N,M = map(int,input().split())
    S = []
    RHS = []
    for i in range(N):
        s = str(input())
        S.append(s)
        temp = RollingHash(s,base1,mod1)
        RHS.append(temp.get(0,M))

    
    ans = set([])
    mae = S[0]
    for i in range(26):
        na = chr(i+97) + mae
        #print(na)
        frh = RollingHash(na[:-1],base1,mod1)
        first = frh.get(0,M)
        srh = RollingHash(na[1:],base1,mod1)
        second = srh.get(0,M)
        for j in range(1,N):
            if RHS[j] == first or RHS[j] == second:
                continue
            else:
                break
        else:
            ans.add(na)
    
    ato = S[0]
    for i in range(26):
        na = ato + chr(i+97)
        #print(na)
        frh = RollingHash(na[:-1],base1,mod1)
        first = frh.get(0,M)
        srh = RollingHash(na[1:],base1,mod1)
        second = srh.get(0,M)
        for j in range(1,N):
            #print(RHS[j],first,second)
            if RHS[j] == first or RHS[j] == second:
                continue
            else:
                break
        else:
            ans.add(na)

    print(len(ans))


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