結果

問題 No.1425 Yet Another Cyclic Shifts Sorting
ユーザー sgswsgsw
提出日時 2021-08-15 00:38:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 173 ms / 2,000 ms
コード長 1,407 bytes
コンパイル時間 269 ms
コンパイル使用メモリ 82,892 KB
実行使用メモリ 107,648 KB
最終ジャッジ日時 2024-04-15 22:35:24
合計ジャッジ時間 6,029 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
51,840 KB
testcase_01 AC 41 ms
52,352 KB
testcase_02 AC 43 ms
51,840 KB
testcase_03 AC 43 ms
52,096 KB
testcase_04 AC 41 ms
52,096 KB
testcase_05 AC 41 ms
52,096 KB
testcase_06 AC 42 ms
52,096 KB
testcase_07 AC 42 ms
51,840 KB
testcase_08 AC 42 ms
52,096 KB
testcase_09 AC 41 ms
51,840 KB
testcase_10 AC 43 ms
52,352 KB
testcase_11 AC 41 ms
52,096 KB
testcase_12 AC 43 ms
52,096 KB
testcase_13 AC 44 ms
52,224 KB
testcase_14 AC 41 ms
52,096 KB
testcase_15 AC 41 ms
52,352 KB
testcase_16 AC 43 ms
52,096 KB
testcase_17 AC 42 ms
52,096 KB
testcase_18 AC 42 ms
52,224 KB
testcase_19 AC 43 ms
52,096 KB
testcase_20 AC 42 ms
51,840 KB
testcase_21 AC 41 ms
52,352 KB
testcase_22 AC 95 ms
101,376 KB
testcase_23 AC 53 ms
69,248 KB
testcase_24 AC 54 ms
67,200 KB
testcase_25 AC 98 ms
104,960 KB
testcase_26 AC 108 ms
101,956 KB
testcase_27 AC 112 ms
106,368 KB
testcase_28 AC 128 ms
105,220 KB
testcase_29 AC 77 ms
81,152 KB
testcase_30 AC 76 ms
76,160 KB
testcase_31 AC 128 ms
105,088 KB
testcase_32 AC 77 ms
80,256 KB
testcase_33 AC 62 ms
65,024 KB
testcase_34 AC 84 ms
83,584 KB
testcase_35 AC 119 ms
107,648 KB
testcase_36 AC 132 ms
102,800 KB
testcase_37 AC 74 ms
73,344 KB
testcase_38 AC 172 ms
107,164 KB
testcase_39 AC 57 ms
64,768 KB
testcase_40 AC 145 ms
104,576 KB
testcase_41 AC 94 ms
83,584 KB
testcase_42 AC 109 ms
89,728 KB
testcase_43 AC 64 ms
66,556 KB
testcase_44 AC 78 ms
73,216 KB
testcase_45 AC 173 ms
106,976 KB
testcase_46 AC 170 ms
106,844 KB
testcase_47 AC 167 ms
107,172 KB
testcase_48 AC 169 ms
106,796 KB
testcase_49 AC 171 ms
106,840 KB
testcase_50 AC 42 ms
52,224 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

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] = (not a[0] <= a[1]) + (not a[1] <= a[0])
            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