結果

問題 No.1425 Yet Another Cyclic Shifts Sorting
ユーザー convexineqconvexineq
提出日時 2021-03-13 00:16:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 117 ms / 2,000 ms
コード長 554 bytes
コンパイル時間 182 ms
コンパイル使用メモリ 81,792 KB
実行使用メモリ 110,260 KB
最終ジャッジ日時 2024-10-14 16:29:25
合計ジャッジ時間 5,024 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 48
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
*a, = map(int,input().split())
v = 10**10
p = [0]*n
for i in range(n)[::-1]:
    if a[i] > v: break
    p[i] = 1
    v = a[i]
v = -1
q = [0]*n
for i in range(n):
    if a[i] < v: break
    q[i] = 1
    v = a[i]
idx = i
v = q[idx]
for i in range(idx,n):
    if a[i] < v: break
    q[i] = 1
    v = a[i]

L,R = a[0],a[idx-1]
#print(L,R,idx)
a.append(10**10)
p.append(1)
ans = 2
for i in range(idx+1,n+1):
    if q[i-1] == p[i] == 1 and a[i-1] <= L and R <= a[i]:
        ans = 1
#print(p)
#print(idx,q)
if p[0] == 1:
    ans = 0
print(ans)
0