結果

問題 No.2102 [Cherry Alpha *] Conditional Reflection
ユーザー roarisroaris
提出日時 2022-10-15 06:05:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 890 ms / 3,000 ms
コード長 2,186 bytes
コンパイル時間 461 ms
コンパイル使用メモリ 87,000 KB
実行使用メモリ 258,140 KB
最終ジャッジ日時 2023-09-09 02:12:43
合計ジャッジ時間 47,394 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
71,756 KB
testcase_01 AC 92 ms
71,776 KB
testcase_02 AC 535 ms
94,324 KB
testcase_03 AC 640 ms
99,812 KB
testcase_04 AC 514 ms
93,972 KB
testcase_05 AC 415 ms
88,916 KB
testcase_06 AC 580 ms
97,456 KB
testcase_07 AC 556 ms
87,628 KB
testcase_08 AC 247 ms
79,892 KB
testcase_09 AC 581 ms
93,764 KB
testcase_10 AC 349 ms
84,564 KB
testcase_11 AC 356 ms
86,388 KB
testcase_12 AC 477 ms
91,216 KB
testcase_13 AC 701 ms
101,076 KB
testcase_14 AC 482 ms
91,308 KB
testcase_15 AC 575 ms
96,172 KB
testcase_16 AC 768 ms
104,784 KB
testcase_17 AC 417 ms
83,536 KB
testcase_18 AC 602 ms
91,404 KB
testcase_19 AC 382 ms
89,284 KB
testcase_20 AC 731 ms
101,300 KB
testcase_21 AC 316 ms
81,660 KB
testcase_22 AC 882 ms
111,012 KB
testcase_23 AC 814 ms
109,344 KB
testcase_24 AC 843 ms
110,012 KB
testcase_25 AC 844 ms
109,384 KB
testcase_26 AC 880 ms
110,860 KB
testcase_27 AC 855 ms
108,664 KB
testcase_28 AC 864 ms
109,592 KB
testcase_29 AC 868 ms
109,984 KB
testcase_30 AC 854 ms
110,064 KB
testcase_31 AC 821 ms
108,952 KB
testcase_32 AC 838 ms
111,324 KB
testcase_33 AC 858 ms
109,916 KB
testcase_34 AC 890 ms
111,124 KB
testcase_35 AC 871 ms
109,884 KB
testcase_36 AC 843 ms
108,504 KB
testcase_37 AC 860 ms
109,416 KB
testcase_38 AC 829 ms
109,864 KB
testcase_39 AC 818 ms
108,660 KB
testcase_40 AC 823 ms
110,032 KB
testcase_41 AC 811 ms
109,180 KB
testcase_42 AC 686 ms
95,748 KB
testcase_43 AC 686 ms
96,004 KB
testcase_44 AC 693 ms
95,932 KB
testcase_45 AC 691 ms
95,756 KB
testcase_46 AC 690 ms
95,928 KB
testcase_47 AC 622 ms
88,468 KB
testcase_48 AC 629 ms
88,504 KB
testcase_49 AC 632 ms
88,596 KB
testcase_50 AC 623 ms
88,516 KB
testcase_51 AC 621 ms
88,536 KB
testcase_52 AC 439 ms
256,568 KB
testcase_53 AC 455 ms
256,320 KB
testcase_54 AC 422 ms
256,648 KB
testcase_55 AC 570 ms
79,184 KB
testcase_56 AC 577 ms
79,252 KB
testcase_57 AC 573 ms
79,220 KB
testcase_58 AC 589 ms
258,140 KB
testcase_59 AC 831 ms
113,572 KB
testcase_60 AC 222 ms
78,928 KB
testcase_61 AC 575 ms
79,176 KB
testcase_62 AC 176 ms
79,208 KB
testcase_63 AC 299 ms
79,244 KB
testcase_64 AC 293 ms
79,200 KB
testcase_65 AC 306 ms
80,208 KB
testcase_66 AC 556 ms
79,200 KB
testcase_67 AC 392 ms
80,336 KB
testcase_68 AC 572 ms
79,120 KB
testcase_69 AC 394 ms
80,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from collections import *

class RollingHash1:
    def __init__(self, s):
        self.base = 17
        self.mod = 10**9+7
        self.acc = [0]
        self.power = [1]
        
        for i in range(len(s)):
            self.acc.append((self.acc[-1]*self.base%self.mod+(ord(s[i])-ord('a')+1))%self.mod)
            self.power.append(self.power[-1]*self.base%self.mod)
    
    def get(self, l, r):
        return (self.acc[r]-self.acc[l]*self.power[r-l])%self.mod

class RollingHash2:
    def __init__(self, s):
        self.base = 31
        self.mod = 998244353
        self.acc = [0]
        self.power = [1]
        
        for i in range(len(s)):
            self.acc.append((self.acc[-1]*self.base%self.mod+(ord(s[i])-ord('a')+1))%self.mod)
            self.power.append(self.power[-1]*self.base%self.mod)
    
    def get(self, l, r):
        return (self.acc[r]-self.acc[l]*self.power[r-l])%self.mod

N = int(input())
ws = set()

for _ in range(N):
    S = input()[:-1]
    n = len(S)
    rh1 = RollingHash1(S)
    rh2 = RollingHash2(S)
    h1 = rh1.get(0, n)
    h2 = rh2.get(0, n)
    
    if (h1, h2) in ws:
        print('Yes')
    else:
        for i in range(n-1):
            nh1 = h1
            nh1 -= (ord(S[i])-ord('a'))*rh1.power[n-1-i]%rh1.mod
            nh1 %= rh1.mod
            nh1 -= (ord(S[i+1])-ord('a'))*rh1.power[n-2-i]%rh1.mod
            nh1 %= rh1.mod
            nh1 += (ord(S[i+1])-ord('a'))*rh1.power[n-1-i]%rh1.mod
            nh1 %= rh1.mod
            nh1 += (ord(S[i])-ord('a'))*rh1.power[n-2-i]%rh1.mod
            nh1 %= rh1.mod
            
            nh2 = h2
            nh2 -= (ord(S[i])-ord('a'))*rh2.power[n-1-i]%rh2.mod
            nh2 %= rh2.mod
            nh2 -= (ord(S[i+1])-ord('a'))*rh2.power[n-2-i]%rh2.mod
            nh2 %= rh2.mod
            nh2 += (ord(S[i+1])-ord('a'))*rh2.power[n-1-i]%rh2.mod
            nh2 %= rh2.mod
            nh2 += (ord(S[i])-ord('a'))*rh2.power[n-2-i]%rh2.mod
            nh2 %= rh2.mod
            
            if (nh1, nh2) in ws:
                print('Yes')
                break
        else:
            print('No')
        
    ws.add((h1, h2))
0