結果

問題 No.1859 ><<<
ユーザー ShirotsumeShirotsume
提出日時 2021-11-27 00:59:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 228 ms / 2,000 ms
コード長 850 bytes
コンパイル時間 319 ms
コンパイル使用メモリ 87,096 KB
実行使用メモリ 172,896 KB
最終ジャッジ日時 2023-09-17 22:56:12
合計ジャッジ時間 11,303 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,256 KB
testcase_01 AC 72 ms
71,040 KB
testcase_02 AC 71 ms
71,216 KB
testcase_03 AC 71 ms
71,348 KB
testcase_04 AC 227 ms
172,368 KB
testcase_05 AC 218 ms
172,764 KB
testcase_06 AC 225 ms
172,136 KB
testcase_07 AC 216 ms
172,896 KB
testcase_08 AC 223 ms
172,556 KB
testcase_09 AC 216 ms
172,636 KB
testcase_10 AC 111 ms
90,848 KB
testcase_11 AC 179 ms
137,884 KB
testcase_12 AC 167 ms
130,668 KB
testcase_13 AC 134 ms
107,156 KB
testcase_14 AC 174 ms
112,368 KB
testcase_15 AC 204 ms
155,024 KB
testcase_16 AC 219 ms
163,468 KB
testcase_17 AC 185 ms
116,740 KB
testcase_18 AC 216 ms
163,396 KB
testcase_19 AC 177 ms
116,460 KB
testcase_20 AC 196 ms
155,020 KB
testcase_21 AC 208 ms
167,064 KB
testcase_22 AC 206 ms
163,980 KB
testcase_23 AC 199 ms
154,252 KB
testcase_24 AC 215 ms
165,944 KB
testcase_25 AC 228 ms
163,964 KB
testcase_26 AC 209 ms
155,440 KB
testcase_27 AC 225 ms
163,556 KB
testcase_28 AC 210 ms
158,104 KB
testcase_29 AC 214 ms
158,336 KB
testcase_30 AC 208 ms
154,668 KB
testcase_31 AC 206 ms
154,188 KB
testcase_32 AC 227 ms
166,752 KB
testcase_33 AC 210 ms
155,036 KB
testcase_34 AC 222 ms
163,392 KB
testcase_35 AC 222 ms
167,280 KB
testcase_36 AC 219 ms
166,988 KB
testcase_37 AC 211 ms
154,844 KB
testcase_38 AC 226 ms
167,748 KB
testcase_39 AC 221 ms
167,132 KB
testcase_40 AC 212 ms
165,900 KB
testcase_41 AC 215 ms
167,120 KB
testcase_42 AC 203 ms
154,156 KB
testcase_43 AC 212 ms
163,644 KB
testcase_44 AC 210 ms
163,544 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def Z_algorithm(S):
    N=len(S)
    arr = [0]*N
    arr[0] = N
    i,j = 1,0
    while i<N:
        while i+j<N and S[j]==S[i+j]:
            j += 1
        arr[i]=j
        if not j:
            i += 1
            continue
        k = 1
        while i+k<N and k+arr[k]<j:
            arr[i+k] = arr[k]
            k += 1
        i += k; j -= k
    return arr

def solve(n, a, s):
    t = []
    a = a + a
    for i in range(2 * n - 2):
        if a[i] < a[i + 1]:
            t.append('<')
        else:
            t.append('>')
    n -= 1
    t = ''.join(t)
    l = Z_algorithm(s + t)[n:]
    ans = -1
    #print(''.join(list(s + t)[n:]))
    #print(l)
    for i in range(n + 1):
        if l[i] >= n:
            ans = i
            break
    return ans


n = int(input())
a = list(map(int,input().split()))
s = input()

print(solve(n, a, s))
 
0