結果

問題 No.2102 [Cherry Alpha *] Conditional Reflection
ユーザー flygonflygon
提出日時 2022-10-15 14:34:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 583 ms / 3,000 ms
コード長 1,507 bytes
コンパイル時間 367 ms
コンパイル使用メモリ 87,196 KB
実行使用メモリ 128,020 KB
最終ジャッジ日時 2023-09-09 02:38:03
合計ジャッジ時間 32,979 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
72,360 KB
testcase_01 AC 89 ms
72,132 KB
testcase_02 AC 419 ms
106,608 KB
testcase_03 AC 455 ms
112,156 KB
testcase_04 AC 437 ms
107,344 KB
testcase_05 AC 386 ms
101,088 KB
testcase_06 AC 434 ms
109,688 KB
testcase_07 AC 305 ms
95,084 KB
testcase_08 AC 288 ms
89,928 KB
testcase_09 AC 379 ms
103,512 KB
testcase_10 AC 329 ms
94,408 KB
testcase_11 AC 262 ms
90,104 KB
testcase_12 AC 373 ms
101,104 KB
testcase_13 AC 476 ms
111,232 KB
testcase_14 AC 397 ms
104,136 KB
testcase_15 AC 469 ms
112,184 KB
testcase_16 AC 528 ms
121,900 KB
testcase_17 AC 254 ms
90,364 KB
testcase_18 AC 343 ms
99,868 KB
testcase_19 AC 321 ms
96,488 KB
testcase_20 AC 473 ms
114,348 KB
testcase_21 AC 361 ms
97,220 KB
testcase_22 AC 569 ms
127,772 KB
testcase_23 AC 582 ms
127,536 KB
testcase_24 AC 560 ms
126,932 KB
testcase_25 AC 559 ms
125,836 KB
testcase_26 AC 556 ms
126,244 KB
testcase_27 AC 574 ms
126,240 KB
testcase_28 AC 569 ms
126,316 KB
testcase_29 AC 567 ms
126,932 KB
testcase_30 AC 567 ms
125,524 KB
testcase_31 AC 583 ms
125,660 KB
testcase_32 AC 553 ms
125,752 KB
testcase_33 AC 566 ms
125,656 KB
testcase_34 AC 567 ms
126,972 KB
testcase_35 AC 571 ms
126,948 KB
testcase_36 AC 564 ms
126,812 KB
testcase_37 AC 571 ms
126,260 KB
testcase_38 AC 577 ms
126,736 KB
testcase_39 AC 575 ms
126,908 KB
testcase_40 AC 569 ms
126,744 KB
testcase_41 AC 564 ms
126,608 KB
testcase_42 AC 388 ms
107,640 KB
testcase_43 AC 385 ms
107,564 KB
testcase_44 AC 389 ms
107,648 KB
testcase_45 AC 396 ms
107,216 KB
testcase_46 AC 396 ms
107,484 KB
testcase_47 AC 330 ms
98,188 KB
testcase_48 AC 335 ms
98,472 KB
testcase_49 AC 338 ms
98,224 KB
testcase_50 AC 326 ms
98,240 KB
testcase_51 AC 327 ms
98,212 KB
testcase_52 AC 236 ms
118,312 KB
testcase_53 AC 239 ms
118,172 KB
testcase_54 AC 238 ms
117,948 KB
testcase_55 AC 215 ms
85,528 KB
testcase_56 AC 213 ms
85,976 KB
testcase_57 AC 213 ms
85,748 KB
testcase_58 AC 217 ms
103,160 KB
testcase_59 AC 554 ms
128,020 KB
testcase_60 AC 268 ms
89,736 KB
testcase_61 AC 215 ms
85,780 KB
testcase_62 AC 149 ms
79,516 KB
testcase_63 AC 250 ms
90,780 KB
testcase_64 AC 252 ms
90,992 KB
testcase_65 AC 254 ms
91,556 KB
testcase_66 AC 213 ms
85,824 KB
testcase_67 AC 407 ms
102,884 KB
testcase_68 AC 203 ms
85,680 KB
testcase_69 AC 404 ms
102,880 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
n = int(input())
s = [""]*n
L = 0
for i in range(n):
  s[i] = [ord(a) - ord("a")+ 1 for a in input()]
  L = max(L, len(s[i]))
  
p = 10**9+7
beta = randint(2, p-1)
q = 10**9+9
gamma = randint(2, q-1)
Bp = [1]*L
Bq= [1]*L
Hp = Hasher(L, beta, p)
Hq = Hasher(L, gamma, q)

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
  Bq[j] *= gamma-1
  Bp[j] %= p
  Bq[j] %= q

E = set()
ans = [0]*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] = 1
    continue

  lensi = len(s[i])
  for j in range(lensi-1):
    kp = (hp + Bp[lensi-j-2]*(s[i][j+1] - s[i][j]))%p
    kq = (hq + Bq[lensi-j-2]*(s[i][j+1] - s[i][j]))%q
    if hashing(kp, kq) in E:
      ans[i] = 1
  E.add(h)

for i in ans:
  print('Yes') if i else print('No')
0