結果

問題 No.1425 Yet Another Cyclic Shifts Sorting
ユーザー roarisroaris
提出日時 2021-03-13 00:10:37
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 611 bytes
コンパイル時間 165 ms
コンパイル使用メモリ 81,888 KB
実行使用メモリ 131,516 KB
最終ジャッジ日時 2024-10-14 14:34:35
合計ジャッジ時間 5,265 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 46 WA * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))

if A==list(sorted(A)):
    print(0)
    exit()

down = [0, 0]

for i in range(N-1):
    down.append(down[-1]+(1 if A[i]>A[i+1] else 0))

M = [0]

for i in range(N):
    M.append(max(M[-1], A[i]))
    
m = min(A)

if down[N]==1:
    for i in range(N-1):
        if A[i]>A[i+1] and A[i+1]==m and A[-1]<=A[0]:
            print(1)
            exit()

for i in range(N-1, 0, -1):
    if i==N-1 or A[i]<=A[i+1]:
        if down[i]==1 and M[i]<=A[i]:
            print(1)
            exit()
    else:
        break

print(2)
0