結果

問題 No.1859 ><<<
ユーザー roarisroaris
提出日時 2022-02-26 20:44:30
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 215 ms / 2,000 ms
コード長 767 bytes
コンパイル時間 276 ms
コンパイル使用メモリ 87,304 KB
実行使用メモリ 147,112 KB
最終ジャッジ日時 2023-09-18 00:17:40
合計ジャッジ時間 10,930 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,316 KB
testcase_01 AC 72 ms
71,556 KB
testcase_02 AC 70 ms
71,164 KB
testcase_03 AC 70 ms
71,520 KB
testcase_04 AC 215 ms
146,724 KB
testcase_05 AC 201 ms
146,864 KB
testcase_06 AC 209 ms
146,724 KB
testcase_07 AC 201 ms
146,856 KB
testcase_08 AC 205 ms
146,784 KB
testcase_09 AC 199 ms
147,112 KB
testcase_10 AC 106 ms
86,296 KB
testcase_11 AC 163 ms
102,908 KB
testcase_12 AC 150 ms
114,300 KB
testcase_13 AC 121 ms
98,776 KB
testcase_14 AC 160 ms
106,448 KB
testcase_15 AC 190 ms
130,144 KB
testcase_16 AC 202 ms
136,284 KB
testcase_17 AC 165 ms
109,544 KB
testcase_18 AC 202 ms
136,012 KB
testcase_19 AC 164 ms
106,872 KB
testcase_20 AC 180 ms
130,372 KB
testcase_21 AC 191 ms
139,368 KB
testcase_22 AC 188 ms
136,172 KB
testcase_23 AC 182 ms
130,076 KB
testcase_24 AC 198 ms
138,592 KB
testcase_25 AC 206 ms
136,200 KB
testcase_26 AC 195 ms
130,532 KB
testcase_27 AC 207 ms
136,172 KB
testcase_28 AC 197 ms
135,580 KB
testcase_29 AC 198 ms
135,412 KB
testcase_30 AC 192 ms
129,840 KB
testcase_31 AC 189 ms
129,848 KB
testcase_32 AC 204 ms
139,060 KB
testcase_33 AC 190 ms
130,144 KB
testcase_34 AC 196 ms
135,956 KB
testcase_35 AC 209 ms
139,352 KB
testcase_36 AC 214 ms
139,188 KB
testcase_37 AC 191 ms
130,232 KB
testcase_38 AC 208 ms
139,560 KB
testcase_39 AC 210 ms
139,124 KB
testcase_40 AC 198 ms
138,504 KB
testcase_41 AC 202 ms
139,188 KB
testcase_42 AC 186 ms
130,140 KB
testcase_43 AC 196 ms
136,452 KB
testcase_44 AC 198 ms
135,912 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

def z_algo(s):
    c = 0
    n = len(s)
    z = [0]*n
    
    for i in range(1, n):
        l = i-c
        
        if i+z[l]<c+z[c]:
            z[i] = z[l]
        else:
            j = max(0, c+z[c]-i)
            
            while i+j<n and s[j]==s[i+j]:
                j += 1
            
            z[i] = j
            c = i
    
    z[0] = n
    return z

N = int(input())
A = list(map(int, input().split()))
S = input()[:-1]
l = []

for i in range(N):
    if A[i]<A[(i+1)%N]:
        l.append('<')
    else:
        l.append('>')

s = ''.join(l)
z = z_algo(''.join([S, s, s]))
ans = N+10

for i in range(N-1, 2*N-1):
    if z[i]>=N-1:
        ans = min(ans, i-N+1)

if ans==N+10:
    print(-1)
else:
    print(ans)
0