結果

問題 No.1425 Yet Another Cyclic Shifts Sorting
ユーザー 👑 箱星箱星
提出日時 2020-12-09 21:58:37
言語 Kotlin
(1.9.23)
結果
WA  
実行時間 -
コード長 1,540 bytes
コンパイル時間 14,042 ms
コンパイル使用メモリ 445,532 KB
実行使用メモリ 66,020 KB
最終ジャッジ日時 2023-10-21 12:41:11
合計ジャッジ時間 37,064 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 289 ms
51,744 KB
testcase_01 AC 288 ms
51,736 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 300 ms
51,748 KB
testcase_05 AC 299 ms
51,752 KB
testcase_06 AC 299 ms
51,748 KB
testcase_07 AC 295 ms
51,748 KB
testcase_08 AC 299 ms
51,744 KB
testcase_09 AC 295 ms
51,756 KB
testcase_10 AC 294 ms
51,756 KB
testcase_11 AC 296 ms
51,740 KB
testcase_12 AC 297 ms
51,732 KB
testcase_13 AC 290 ms
51,744 KB
testcase_14 AC 296 ms
51,744 KB
testcase_15 AC 293 ms
51,756 KB
testcase_16 AC 297 ms
51,748 KB
testcase_17 AC 306 ms
51,752 KB
testcase_18 AC 302 ms
51,752 KB
testcase_19 AC 299 ms
51,752 KB
testcase_20 AC 309 ms
51,756 KB
testcase_21 AC 296 ms
51,752 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 447 ms
57,536 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 439 ms
57,540 KB
testcase_30 AC 447 ms
58,024 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 386 ms
54,376 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 508 ms
66,020 KB
testcase_37 AC 431 ms
57,676 KB
testcase_38 AC 546 ms
61,836 KB
testcase_39 AC 378 ms
54,380 KB
testcase_40 AC 523 ms
63,852 KB
testcase_41 AC 459 ms
57,528 KB
testcase_42 AC 468 ms
61,716 KB
testcase_43 AC 394 ms
54,376 KB
testcase_44 AC 436 ms
57,672 KB
testcase_45 AC 529 ms
61,832 KB
testcase_46 AC 536 ms
61,816 KB
testcase_47 AC 527 ms
61,824 KB
testcase_48 AC 541 ms
61,984 KB
testcase_49 AC 536 ms
61,896 KB
testcase_50 AC 296 ms
51,748 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