結果

問題 No.2102 [Cherry Alpha *] Conditional Reflection
ユーザー 👑 KazunKazun
提出日時 2022-07-26 21:03:45
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 480 ms / 3,000 ms
コード長 1,616 bytes
コンパイル時間 788 ms
コンパイル使用メモリ 86,556 KB
実行使用メモリ 129,160 KB
最終ジャッジ日時 2023-09-08 20:00:55
合計ジャッジ時間 28,702 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
71,588 KB
testcase_01 AC 85 ms
71,572 KB
testcase_02 AC 340 ms
104,856 KB
testcase_03 AC 361 ms
109,072 KB
testcase_04 AC 341 ms
106,272 KB
testcase_05 AC 301 ms
101,200 KB
testcase_06 AC 355 ms
108,952 KB
testcase_07 AC 255 ms
94,780 KB
testcase_08 AC 222 ms
90,184 KB
testcase_09 AC 321 ms
102,012 KB
testcase_10 AC 252 ms
92,968 KB
testcase_11 AC 205 ms
89,280 KB
testcase_12 AC 296 ms
99,220 KB
testcase_13 AC 369 ms
110,344 KB
testcase_14 AC 311 ms
103,472 KB
testcase_15 AC 387 ms
112,516 KB
testcase_16 AC 423 ms
121,648 KB
testcase_17 AC 210 ms
88,800 KB
testcase_18 AC 288 ms
99,376 KB
testcase_19 AC 256 ms
95,552 KB
testcase_20 AC 375 ms
112,120 KB
testcase_21 AC 270 ms
97,676 KB
testcase_22 AC 445 ms
124,892 KB
testcase_23 AC 451 ms
125,060 KB
testcase_24 AC 443 ms
125,496 KB
testcase_25 AC 458 ms
124,872 KB
testcase_26 AC 441 ms
124,668 KB
testcase_27 AC 480 ms
123,852 KB
testcase_28 AC 455 ms
124,700 KB
testcase_29 AC 460 ms
125,560 KB
testcase_30 AC 460 ms
124,820 KB
testcase_31 AC 461 ms
125,048 KB
testcase_32 AC 460 ms
123,528 KB
testcase_33 AC 468 ms
124,312 KB
testcase_34 AC 478 ms
124,868 KB
testcase_35 AC 473 ms
124,344 KB
testcase_36 AC 471 ms
125,052 KB
testcase_37 AC 454 ms
124,288 KB
testcase_38 AC 468 ms
124,728 KB
testcase_39 AC 464 ms
125,436 KB
testcase_40 AC 457 ms
124,804 KB
testcase_41 AC 464 ms
125,080 KB
testcase_42 AC 336 ms
105,812 KB
testcase_43 AC 327 ms
105,724 KB
testcase_44 AC 325 ms
105,984 KB
testcase_45 AC 319 ms
105,668 KB
testcase_46 AC 331 ms
105,812 KB
testcase_47 AC 283 ms
97,132 KB
testcase_48 AC 284 ms
97,152 KB
testcase_49 AC 279 ms
97,392 KB
testcase_50 AC 285 ms
97,216 KB
testcase_51 AC 280 ms
97,060 KB
testcase_52 AC 230 ms
117,432 KB
testcase_53 AC 227 ms
117,908 KB
testcase_54 AC 229 ms
117,512 KB
testcase_55 AC 199 ms
85,548 KB
testcase_56 AC 201 ms
85,560 KB
testcase_57 AC 200 ms
85,488 KB
testcase_58 AC 219 ms
102,696 KB
testcase_59 AC 455 ms
129,160 KB
testcase_60 AC 230 ms
89,748 KB
testcase_61 AC 200 ms
85,456 KB
testcase_62 AC 120 ms
78,824 KB
testcase_63 AC 244 ms
90,128 KB
testcase_64 AC 245 ms
89,916 KB
testcase_65 AC 259 ms
89,792 KB
testcase_66 AC 202 ms
85,564 KB
testcase_67 AC 341 ms
103,904 KB
testcase_68 AC 191 ms
85,516 KB
testcase_69 AC 346 ms
104,156 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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
#==================================================
def hashing(a,b):
    return a*q+b

#==================================================
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); Hp=Hasher(L, beta, p)
q=10**9+9; gamma=randint(2,q-1); Hq=Hasher(L, gamma, q)

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

for j in range(1,L):
    Bp[j]=Bp[j-1]*beta %p
    Bq[j]=Bq[j-1]*gamma%q

for j in range(L):
    Bp[j]*=beta-1 ; Bp[j]%=p
    Bq[j]*=gamma-1; Bq[j]%=q

E=set()
Ans=["No"]*N
for i in range(N):
    hp=Hp.encode(S[i]); hq=Hq.encode(S[i])

    h=hashing(hp,hq)
    if h in E:
        Ans[i]="Yes"

    for j in range(len(S[i])-1):
        kp=(hp+Bp[len(S[i])-j-2]*(S[i][j+1]-S[i][j]))%p
        kq=(hq+Bq[len(S[i])-j-2]*(S[i][j+1]-S[i][j]))%q

        if hashing(kp,kq) in E:
            Ans[i]="Yes"

    E.add(h)

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