結果

問題 No.1425 Yet Another Cyclic Shifts Sorting
ユーザー sgswsgsw
提出日時 2021-08-15 00:36:07
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,409 bytes
コンパイル時間 228 ms
コンパイル使用メモリ 82,380 KB
実行使用メモリ 107,720 KB
最終ジャッジ日時 2024-04-15 22:33:16
合計ジャッジ時間 5,932 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
52,224 KB
testcase_01 AC 41 ms
52,352 KB
testcase_02 AC 44 ms
52,224 KB
testcase_03 AC 41 ms
52,480 KB
testcase_04 AC 41 ms
52,096 KB
testcase_05 AC 41 ms
52,096 KB
testcase_06 AC 41 ms
51,968 KB
testcase_07 AC 42 ms
52,352 KB
testcase_08 AC 41 ms
51,968 KB
testcase_09 AC 41 ms
51,968 KB
testcase_10 AC 41 ms
52,096 KB
testcase_11 AC 40 ms
51,712 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 41 ms
52,352 KB
testcase_15 AC 40 ms
51,968 KB
testcase_16 AC 40 ms
52,224 KB
testcase_17 AC 40 ms
51,712 KB
testcase_18 AC 40 ms
52,352 KB
testcase_19 AC 39 ms
51,712 KB
testcase_20 AC 41 ms
51,712 KB
testcase_21 AC 41 ms
52,224 KB
testcase_22 AC 86 ms
101,632 KB
testcase_23 AC 53 ms
69,120 KB
testcase_24 AC 51 ms
67,604 KB
testcase_25 AC 91 ms
104,868 KB
testcase_26 AC 101 ms
101,828 KB
testcase_27 AC 109 ms
106,180 KB
testcase_28 AC 121 ms
105,308 KB
testcase_29 AC 73 ms
81,332 KB
testcase_30 AC 69 ms
76,032 KB
testcase_31 AC 123 ms
104,980 KB
testcase_32 AC 72 ms
80,484 KB
testcase_33 AC 58 ms
65,280 KB
testcase_34 AC 78 ms
83,456 KB
testcase_35 AC 113 ms
107,720 KB
testcase_36 AC 128 ms
102,340 KB
testcase_37 AC 73 ms
74,016 KB
testcase_38 AC 162 ms
107,256 KB
testcase_39 AC 60 ms
65,560 KB
testcase_40 AC 140 ms
104,608 KB
testcase_41 AC 87 ms
83,656 KB
testcase_42 AC 103 ms
89,476 KB
testcase_43 AC 62 ms
67,572 KB
testcase_44 AC 71 ms
73,296 KB
testcase_45 AC 166 ms
107,212 KB
testcase_46 AC 163 ms
106,228 KB
testcase_47 AC 165 ms
106,980 KB
testcase_48 AC 164 ms
106,888 KB
testcase_49 AC 162 ms
106,876 KB
testcase_50 AC 39 ms
52,996 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

'''
    Python3(PyPy3) Template for Programming-Contest.

    author : sgsw

    generated : 2021/08/14   
    when : 23:49:30

'''


def input():
    return sys.stdin.readline().rstrip()


DXY = [(0, -1), (1, 0), (0, 1), (-1, 0)]  # LDRU
mod = 998244353
inf = 1 << 64

# from atcoder.segtree import SegTree


def main():
    n = int(input())
    a = list(map(int, input().split()))
    if sorted(a) == a:
        print(0)
    else:
        #case 1
        is_sorted = [False]*(n)
        for i in reversed(range(0, n)):
            if i == n - 1:
                is_sorted[i] = True
            else:
                if is_sorted[i + 1] == True and (a[i] <= a[i + 1]):
                    is_sorted[i] = True

        dp = [0]*(n)
        maxv = a.copy()

        for l in range(1, n):
            maxv[l] = max(maxv[l - 1], maxv[l])
            if l == 1:
                dp[l] = 1
            else:
                dp[l] = (dp[l - 1] - (not a[l - 1] <= a[0])) + \
                    (not a[l - 1] <= a[l]) + (not a[l] <= a[0])

        for i in range(1, n):
            if i != n - 1:
                if maxv[i] <= a[i + 1] and is_sorted[i + 1] and dp[i] == 1:
                    print(1)
                    return
            else:
                if dp[i] == 1:
                    print(1)
                    return
        print(2)

    return 0


if __name__ == "__main__":
    main()
0