結果

問題 No.1425 Yet Another Cyclic Shifts Sorting
ユーザー sgsw
提出日時 2021-08-15 00:36:07
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,409 bytes
コンパイル時間 270 ms
コンパイル使用メモリ 82,404 KB
実行使用メモリ 107,520 KB
最終ジャッジ日時 2024-10-06 04:45:23
合計ジャッジ時間 5,700 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 46 WA * 2
権限があれば一括ダウンロードができます

ソースコード

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