結果

問題 No.2102 [Cherry Alpha *] Conditional Reflection
ユーザー roarisroaris
提出日時 2022-10-15 02:34:49
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 907 ms / 3,000 ms
コード長 2,247 bytes
コンパイル時間 801 ms
コンパイル使用メモリ 87,180 KB
実行使用メモリ 258,348 KB
最終ジャッジ日時 2023-09-09 01:59:15
合計ジャッジ時間 50,281 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 110 ms
73,404 KB
testcase_01 AC 111 ms
73,224 KB
testcase_02 AC 552 ms
96,352 KB
testcase_03 AC 655 ms
103,164 KB
testcase_04 AC 536 ms
97,624 KB
testcase_05 AC 444 ms
91,196 KB
testcase_06 AC 589 ms
99,172 KB
testcase_07 AC 597 ms
89,328 KB
testcase_08 AC 272 ms
81,708 KB
testcase_09 AC 616 ms
97,784 KB
testcase_10 AC 364 ms
87,060 KB
testcase_11 AC 364 ms
88,504 KB
testcase_12 AC 497 ms
93,964 KB
testcase_13 AC 728 ms
101,784 KB
testcase_14 AC 503 ms
95,076 KB
testcase_15 AC 590 ms
98,284 KB
testcase_16 AC 750 ms
108,508 KB
testcase_17 AC 437 ms
85,644 KB
testcase_18 AC 623 ms
94,636 KB
testcase_19 AC 408 ms
91,752 KB
testcase_20 AC 755 ms
106,020 KB
testcase_21 AC 339 ms
83,780 KB
testcase_22 AC 880 ms
113,060 KB
testcase_23 AC 849 ms
110,988 KB
testcase_24 AC 870 ms
112,472 KB
testcase_25 AC 828 ms
112,012 KB
testcase_26 AC 861 ms
111,552 KB
testcase_27 AC 882 ms
112,896 KB
testcase_28 AC 880 ms
111,996 KB
testcase_29 AC 897 ms
112,964 KB
testcase_30 AC 893 ms
112,460 KB
testcase_31 AC 851 ms
111,936 KB
testcase_32 AC 839 ms
111,608 KB
testcase_33 AC 873 ms
111,916 KB
testcase_34 AC 906 ms
115,144 KB
testcase_35 AC 907 ms
112,544 KB
testcase_36 AC 861 ms
111,572 KB
testcase_37 AC 877 ms
111,060 KB
testcase_38 AC 796 ms
112,020 KB
testcase_39 AC 823 ms
110,912 KB
testcase_40 AC 821 ms
111,688 KB
testcase_41 AC 823 ms
110,720 KB
testcase_42 AC 696 ms
98,652 KB
testcase_43 AC 682 ms
98,452 KB
testcase_44 AC 694 ms
98,732 KB
testcase_45 AC 712 ms
98,448 KB
testcase_46 AC 707 ms
98,452 KB
testcase_47 AC 659 ms
91,268 KB
testcase_48 AC 647 ms
91,000 KB
testcase_49 AC 654 ms
91,016 KB
testcase_50 AC 641 ms
91,016 KB
testcase_51 AC 654 ms
91,268 KB
testcase_52 AC 459 ms
258,304 KB
testcase_53 AC 455 ms
258,348 KB
testcase_54 AC 446 ms
258,120 KB
testcase_55 AC 595 ms
81,308 KB
testcase_56 AC 600 ms
81,252 KB
testcase_57 AC 596 ms
81,272 KB
testcase_58 AC 618 ms
246,212 KB
testcase_59 AC 822 ms
116,660 KB
testcase_60 AC 242 ms
80,904 KB
testcase_61 AC 595 ms
81,424 KB
testcase_62 AC 199 ms
82,648 KB
testcase_63 AC 320 ms
81,904 KB
testcase_64 AC 317 ms
81,568 KB
testcase_65 AC 326 ms
81,772 KB
testcase_66 AC 591 ms
81,440 KB
testcase_67 AC 410 ms
83,420 KB
testcase_68 AC 602 ms
82,480 KB
testcase_69 AC 411 ms
82,360 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

class RollingHash1:
    def __init__(self, s):
        self.base = base1
        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 = base2
        self.mod = 10**9+9
        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()
base1 = 17
base2 = 31

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')+1)*rh1.power[n-1-i]%rh1.mod
            nh1 %= rh1.mod
            nh1 -= (ord(S[i+1])-ord('a')+1)*rh1.power[n-2-i]%rh1.mod
            nh1 %= rh1.mod
            nh1 += (ord(S[i+1])-ord('a')+1)*rh1.power[n-1-i]%rh1.mod
            nh1 %= rh1.mod
            nh1 += (ord(S[i])-ord('a')+1)*rh1.power[n-2-i]%rh1.mod
            nh1 %= rh1.mod
            
            nh2 = h2
            nh2 -= (ord(S[i])-ord('a')+1)*rh2.power[n-1-i]%rh2.mod
            nh2 %= rh2.mod
            nh2 -= (ord(S[i+1])-ord('a')+1)*rh2.power[n-2-i]%rh2.mod
            nh2 %= rh2.mod
            nh2 += (ord(S[i+1])-ord('a')+1)*rh2.power[n-1-i]%rh2.mod
            nh2 %= rh2.mod
            nh2 += (ord(S[i])-ord('a')+1)*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