結果

問題 No.1425 Yet Another Cyclic Shifts Sorting
ユーザー 👑 箱星箱星
提出日時 2020-12-29 06:06:42
言語 Kotlin
(1.9.23)
結果
WA  
実行時間 -
コード長 1,545 bytes
コンパイル時間 12,410 ms
コンパイル使用メモリ 444,648 KB
実行使用メモリ 92,356 KB
最終ジャッジ日時 2024-04-15 05:16:01
合計ジャッジ時間 33,660 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 273 ms
50,056 KB
testcase_02 AC 278 ms
49,928 KB
testcase_03 AC 275 ms
49,948 KB
testcase_04 AC 274 ms
50,088 KB
testcase_05 AC 282 ms
50,096 KB
testcase_06 AC 308 ms
49,888 KB
testcase_07 AC 272 ms
50,004 KB
testcase_08 AC 272 ms
50,012 KB
testcase_09 WA -
testcase_10 AC 280 ms
49,924 KB
testcase_11 AC 277 ms
49,940 KB
testcase_12 AC 274 ms
49,904 KB
testcase_13 AC 276 ms
49,980 KB
testcase_14 AC 276 ms
49,924 KB
testcase_15 AC 282 ms
49,896 KB
testcase_16 AC 281 ms
49,972 KB
testcase_17 AC 277 ms
49,964 KB
testcase_18 WA -
testcase_19 AC 283 ms
50,076 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 483 ms
70,016 KB
testcase_23 AC 406 ms
55,676 KB
testcase_24 AC 407 ms
55,656 KB
testcase_25 AC 479 ms
71,192 KB
testcase_26 AC 498 ms
73,728 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 481 ms
70,944 KB
testcase_37 AC 413 ms
54,992 KB
testcase_38 AC 551 ms
92,160 KB
testcase_39 AC 346 ms
51,340 KB
testcase_40 AC 501 ms
73,884 KB
testcase_41 AC 426 ms
60,188 KB
testcase_42 AC 437 ms
61,864 KB
testcase_43 AC 360 ms
51,860 KB
testcase_44 AC 403 ms
55,128 KB
testcase_45 AC 551 ms
92,356 KB
testcase_46 AC 541 ms
92,132 KB
testcase_47 AC 548 ms
92,224 KB
testcase_48 AC 543 ms
91,972 KB
testcase_49 AC 552 ms
91,972 KB
testcase_50 AC 273 ms
50,040 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 + 1] <= 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