結果

問題 No.1425 Yet Another Cyclic Shifts Sorting
ユーザー H3PO4H3PO4
提出日時 2022-07-26 08:27:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 163 ms / 2,000 ms
コード長 575 bytes
コンパイル時間 419 ms
コンパイル使用メモリ 87,216 KB
実行使用メモリ 106,020 KB
最終ジャッジ日時 2023-09-23 00:07:05
合計ジャッジ時間 8,020 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,464 KB
testcase_01 AC 69 ms
71,460 KB
testcase_02 AC 68 ms
71,480 KB
testcase_03 AC 69 ms
71,476 KB
testcase_04 AC 69 ms
71,392 KB
testcase_05 AC 69 ms
71,512 KB
testcase_06 AC 69 ms
71,452 KB
testcase_07 AC 70 ms
71,116 KB
testcase_08 AC 70 ms
71,408 KB
testcase_09 AC 68 ms
71,360 KB
testcase_10 AC 68 ms
71,624 KB
testcase_11 AC 70 ms
71,476 KB
testcase_12 AC 69 ms
71,460 KB
testcase_13 AC 70 ms
71,556 KB
testcase_14 AC 69 ms
71,140 KB
testcase_15 AC 68 ms
71,340 KB
testcase_16 AC 70 ms
71,552 KB
testcase_17 AC 69 ms
71,520 KB
testcase_18 AC 70 ms
71,556 KB
testcase_19 AC 69 ms
71,524 KB
testcase_20 AC 71 ms
71,276 KB
testcase_21 AC 69 ms
71,484 KB
testcase_22 AC 105 ms
102,436 KB
testcase_23 AC 80 ms
80,692 KB
testcase_24 AC 79 ms
79,724 KB
testcase_25 AC 112 ms
106,020 KB
testcase_26 AC 124 ms
100,940 KB
testcase_27 AC 117 ms
99,708 KB
testcase_28 AC 125 ms
102,408 KB
testcase_29 AC 89 ms
85,176 KB
testcase_30 AC 84 ms
81,956 KB
testcase_31 AC 127 ms
102,676 KB
testcase_32 AC 87 ms
83,932 KB
testcase_33 AC 77 ms
76,168 KB
testcase_34 AC 89 ms
86,312 KB
testcase_35 AC 122 ms
100,424 KB
testcase_36 AC 130 ms
100,912 KB
testcase_37 AC 84 ms
78,900 KB
testcase_38 AC 162 ms
104,760 KB
testcase_39 AC 76 ms
76,220 KB
testcase_40 AC 140 ms
105,540 KB
testcase_41 AC 116 ms
85,736 KB
testcase_42 AC 104 ms
88,812 KB
testcase_43 AC 79 ms
76,316 KB
testcase_44 AC 84 ms
78,240 KB
testcase_45 AC 163 ms
104,824 KB
testcase_46 AC 158 ms
104,384 KB
testcase_47 AC 160 ms
104,972 KB
testcase_48 AC 160 ms
104,648 KB
testcase_49 AC 163 ms
104,512 KB
testcase_50 AC 70 ms
71,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def find_sorted_min_idx(N, A):
    SA = sorted(A)
    for i in range(N - 1, -1, -1):
        if A[i] != SA[i]:
            return i + 1
    return 0


def is_cyclic_shift(N, A):
    ct = 0
    for i in range(N - 1):
        if A[i] > A[i + 1]:
            ct += 1
    return ct == 1 and A[0] >= A[-1]


def solve(N, A):
    sorted_min_idx = find_sorted_min_idx(N, A)
    if not sorted_min_idx:
        return 0
    if is_cyclic_shift(sorted_min_idx, A[:sorted_min_idx]):
        return 1
    return 2


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