結果

問題 No.2102 [Cherry Alpha *] Conditional Reflection
ユーザー 👑 KazunKazun
提出日時 2022-09-10 03:32:14
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,370 bytes
コンパイル時間 247 ms
コンパイル使用メモリ 87,124 KB
実行使用メモリ 122,972 KB
最終ジャッジ日時 2023-09-08 20:08:42
合計ジャッジ時間 23,174 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
71,620 KB
testcase_01 AC 85 ms
71,740 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 199 ms
89,572 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 250 ms
97,156 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 259 ms
103,772 KB
testcase_44 AC 256 ms
103,684 KB
testcase_45 WA -
testcase_46 AC 260 ms
103,940 KB
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 AC 172 ms
109,752 KB
testcase_53 AC 171 ms
109,768 KB
testcase_54 AC 176 ms
109,804 KB
testcase_55 WA -
testcase_56 WA -
testcase_57 AC 166 ms
86,056 KB
testcase_58 AC 162 ms
98,752 KB
testcase_59 AC 353 ms
122,972 KB
testcase_60 AC 194 ms
89,684 KB
testcase_61 AC 158 ms
85,508 KB
testcase_62 AC 107 ms
78,328 KB
testcase_63 AC 197 ms
89,976 KB
testcase_64 AC 205 ms
90,120 KB
testcase_65 AC 215 ms
90,328 KB
testcase_66 AC 166 ms
85,792 KB
testcase_67 AC 288 ms
103,664 KB
testcase_68 AC 155 ms
85,580 KB
testcase_69 AC 283 ms
103,408 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# WA 想定 (1個の素数に対する法しか取っていないため)

class Hasher():
    def __init__(self, length, base, mod):
        self.length=length
        self.base=base
        self.mod=mod

        self.power=pw=[1]*length
        for i in range(1,length):
            pw[i]=(base*pw[i-1])%mod

    def __repr__(self):
        return "length: {}\nbase: {}\nmod: {}".format(self.length, self.base, self.mod)

    def encode(self, S):
        code=0; N=len(S)
        for i in range(N):
            #code+=ord(S[i])*self.power[N-1-i]%self.mod
            code+=S[i]*self.power[N-1-i]%self.mod

        return code%self.mod

    def decode(self, S):
        pass
#==================================================
from random import randint
import sys
input=sys.stdin.readline
write=sys.stdout.write

N=int(input())

S=[""]*N
L=0
for i in range(N):
    S[i]=[ord(a)-ord("a")+1 for a in input()[:-1]]
    L=max(L,len(S[i]))

p=10**9+7; beta=randint(2,p-1); H=Hasher(L, beta, p)

B=[1]*L; Bq=[1]*L

for j in range(1,L):
    B[j]=B[j-1]*beta %p

for j in range(L):
    B[j]*=beta-1 ; B[j]%=p

E=set()
Ans=["No"]*N
for i in range(N):
    h=H.encode(S[i])

    if h in E:
        Ans[i]="Yes"

    for j in range(len(S[i])-1):
        k=(h+B[len(S[i])-j-2]*(S[i][j+1]-S[i][j]))%p

        if k in E:
            Ans[i]="Yes"

    E.add(h)

write("\n".join(Ans))
0