結果

問題 No.1859 ><<<
ユーザー 👑 rin204rin204
提出日時 2022-02-27 14:56:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 286 ms / 2,000 ms
コード長 907 bytes
コンパイル時間 969 ms
コンパイル使用メモリ 87,124 KB
実行使用メモリ 160,716 KB
最終ジャッジ日時 2023-09-19 01:42:00
合計ジャッジ時間 14,773 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,112 KB
testcase_01 AC 77 ms
71,480 KB
testcase_02 AC 74 ms
71,348 KB
testcase_03 AC 73 ms
71,140 KB
testcase_04 AC 286 ms
160,292 KB
testcase_05 AC 272 ms
160,492 KB
testcase_06 AC 262 ms
160,104 KB
testcase_07 AC 256 ms
160,360 KB
testcase_08 AC 261 ms
160,372 KB
testcase_09 AC 259 ms
160,716 KB
testcase_10 AC 116 ms
88,936 KB
testcase_11 AC 190 ms
125,844 KB
testcase_12 AC 172 ms
121,940 KB
testcase_13 AC 137 ms
103,380 KB
testcase_14 AC 174 ms
107,268 KB
testcase_15 AC 221 ms
141,252 KB
testcase_16 AC 246 ms
148,036 KB
testcase_17 AC 182 ms
110,980 KB
testcase_18 AC 241 ms
147,912 KB
testcase_19 AC 187 ms
108,104 KB
testcase_20 AC 220 ms
141,588 KB
testcase_21 AC 242 ms
151,848 KB
testcase_22 AC 220 ms
148,640 KB
testcase_23 AC 223 ms
140,548 KB
testcase_24 AC 227 ms
151,032 KB
testcase_25 AC 244 ms
148,100 KB
testcase_26 AC 221 ms
141,520 KB
testcase_27 AC 251 ms
148,020 KB
testcase_28 AC 231 ms
146,972 KB
testcase_29 AC 241 ms
147,216 KB
testcase_30 AC 230 ms
141,136 KB
testcase_31 AC 227 ms
140,672 KB
testcase_32 AC 256 ms
151,760 KB
testcase_33 AC 233 ms
140,804 KB
testcase_34 AC 219 ms
147,608 KB
testcase_35 AC 248 ms
152,016 KB
testcase_36 AC 244 ms
151,796 KB
testcase_37 AC 242 ms
141,304 KB
testcase_38 AC 267 ms
152,440 KB
testcase_39 AC 248 ms
152,132 KB
testcase_40 AC 229 ms
150,988 KB
testcase_41 AC 220 ms
151,360 KB
testcase_42 AC 238 ms
140,856 KB
testcase_43 AC 236 ms
148,008 KB
testcase_44 AC 248 ms
148,536 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class RollingHash():
    def __init__(self, s, base, mod):
        self.mod = mod
        self.pw = pw = [1]*(len(s)+1)

        l = len(s)
        self.h = h = [0]*(l+1)

        v = 0
        for i in range(l):
            h[i+1] = v = (v * base + ord(s[i])) % mod
        v = 1
        for i in range(l):
            pw[i+1] = v = v * base % mod
    def get(self, l, r):
        return (self.h[r] - self.h[l] * self.pw[r-l]) % self.mod
        
base = 37; mod = 8913478971241

n = int(input())
A = list(map(int, input().split()))
S = input()
T = []
for i in range(n - 1):
    if A[i] > A[i + 1]:
        T.append(">")
    else:
        T.append("<")
if A[n - 1] > A[0]:
    T.append(">")
else:
    T.append("<")
    
T = T + T
rh = RollingHash(T, base, mod)
S = RollingHash(S, base, mod)
S = S.get(0, n - 1)
for i in range(n):
    if rh.get(i, i + n - 1) == S:
        print(i)
        exit()
print(-1)

0