結果

問題 No.1425 Yet Another Cyclic Shifts Sorting
ユーザー 👑 箱星箱星
提出日時 2020-12-09 16:14:34
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 642 ms / 2,000 ms
コード長 1,541 bytes
コンパイル時間 19,770 ms
コンパイル使用メモリ 446,964 KB
実行使用メモリ 92,088 KB
最終ジャッジ日時 2024-04-22 16:48:27
合計ジャッジ時間 34,398 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 267 ms
49,760 KB
testcase_01 AC 265 ms
49,732 KB
testcase_02 AC 265 ms
49,604 KB
testcase_03 AC 267 ms
49,736 KB
testcase_04 AC 273 ms
49,792 KB
testcase_05 AC 264 ms
49,856 KB
testcase_06 AC 262 ms
49,728 KB
testcase_07 AC 265 ms
49,808 KB
testcase_08 AC 257 ms
49,816 KB
testcase_09 AC 259 ms
49,704 KB
testcase_10 AC 259 ms
49,832 KB
testcase_11 AC 260 ms
49,736 KB
testcase_12 AC 281 ms
49,676 KB
testcase_13 AC 261 ms
49,676 KB
testcase_14 AC 264 ms
49,640 KB
testcase_15 AC 260 ms
49,728 KB
testcase_16 AC 261 ms
49,848 KB
testcase_17 AC 263 ms
49,688 KB
testcase_18 AC 270 ms
49,772 KB
testcase_19 AC 271 ms
49,764 KB
testcase_20 AC 258 ms
49,728 KB
testcase_21 AC 261 ms
49,628 KB
testcase_22 AC 488 ms
69,716 KB
testcase_23 AC 413 ms
55,276 KB
testcase_24 AC 390 ms
54,640 KB
testcase_25 AC 498 ms
70,300 KB
testcase_26 AC 524 ms
73,616 KB
testcase_27 AC 505 ms
73,804 KB
testcase_28 AC 642 ms
76,944 KB
testcase_29 AC 401 ms
59,220 KB
testcase_30 AC 395 ms
56,316 KB
testcase_31 AC 567 ms
76,420 KB
testcase_32 AC 426 ms
59,044 KB
testcase_33 AC 329 ms
51,240 KB
testcase_34 AC 407 ms
60,064 KB
testcase_35 AC 494 ms
75,396 KB
testcase_36 AC 520 ms
70,724 KB
testcase_37 AC 374 ms
54,780 KB
testcase_38 AC 564 ms
91,948 KB
testcase_39 AC 330 ms
51,056 KB
testcase_40 AC 526 ms
73,780 KB
testcase_41 AC 439 ms
59,796 KB
testcase_42 AC 409 ms
61,680 KB
testcase_43 AC 337 ms
51,760 KB
testcase_44 AC 393 ms
54,212 KB
testcase_45 AC 531 ms
92,088 KB
testcase_46 AC 558 ms
91,780 KB
testcase_47 AC 607 ms
91,892 KB
testcase_48 AC 513 ms
91,684 KB
testcase_49 AC 528 ms
91,832 KB
testcase_50 AC 258 ms
49,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintWriter
import java.util.*
import kotlin.math.*

fun PrintWriter.solve() {
    val n = nextInt()
    val a = Array(n) { nextInt() }
    // a[i],...,a[n-1]がソートされているかどうか
    val isSorted = Array(n) { false }
    // a[0],...,a[i]における減少回数
    val decrease = Array(n) { 0 }
    // a[0],...,a[i]の最大値
    val max = Array(n) { a[0] }
    isSorted[n - 1] = true
    for (i in n - 2 downTo 0) {
        if (a[i] <= a[i + 1]) {
            isSorted[i] = true
        } else {
            break
        }
    }
    if (isSorted[0]) {
        println(0)
        return
    }
    for (i in 1 until n) {
        decrease[i] = decrease[i - 1]
        if (a[i - 1] > a[i]) decrease[i]++
        max[i] = maxOf(max[i - 1], a[i])
    }
    for (i in 0 until n - 1) {
        if (decrease[i] == 1 && a[i] <= a[0] && isSorted[i + 1] && max[i] <= a[i + 1]) {
            println(1)
            return
        }
    }
    if (decrease[n - 1] == 1 && a[n - 1] <= a[0]) {
        println(1)
        return
    }
    println(2)
}

fun main() {
    val writer = PrintWriter(System.out, false)
    writer.solve()
    writer.flush()
}

// region Scanner
private var st = StringTokenizer("")
private val br = System.`in`.bufferedReader()

fun next(): String {
    while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())
    return st.nextToken()
}

fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextLine() = br.readLine()
fun nextDouble() = next().toDouble()
// endregion
0