結果

問題 No.1425 Yet Another Cyclic Shifts Sorting
ユーザー 👑 箱星箱星
提出日時 2020-12-29 06:14:19
言語 Kotlin
(1.9.23)
結果
WA  
実行時間 -
コード長 1,541 bytes
コンパイル時間 13,484 ms
コンパイル使用メモリ 454,288 KB
実行使用メモリ 98,372 KB
最終ジャッジ日時 2024-04-15 05:22:40
合計ジャッジ時間 33,848 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 267 ms
54,248 KB
testcase_01 AC 266 ms
54,324 KB
testcase_02 AC 265 ms
54,400 KB
testcase_03 AC 269 ms
54,440 KB
testcase_04 AC 268 ms
54,244 KB
testcase_05 AC 267 ms
54,216 KB
testcase_06 AC 271 ms
54,240 KB
testcase_07 AC 266 ms
54,444 KB
testcase_08 AC 267 ms
54,444 KB
testcase_09 AC 267 ms
54,196 KB
testcase_10 AC 267 ms
54,320 KB
testcase_11 WA -
testcase_12 AC 274 ms
54,340 KB
testcase_13 AC 265 ms
54,496 KB
testcase_14 WA -
testcase_15 AC 265 ms
54,436 KB
testcase_16 AC 271 ms
54,212 KB
testcase_17 AC 269 ms
54,456 KB
testcase_18 AC 266 ms
54,340 KB
testcase_19 AC 269 ms
54,204 KB
testcase_20 AC 272 ms
54,264 KB
testcase_21 AC 273 ms
54,348 KB
testcase_22 AC 435 ms
75,816 KB
testcase_23 AC 377 ms
61,740 KB
testcase_24 AC 379 ms
59,608 KB
testcase_25 AC 438 ms
75,868 KB
testcase_26 AC 487 ms
80,068 KB
testcase_27 AC 458 ms
79,768 KB
testcase_28 AC 502 ms
82,036 KB
testcase_29 AC 400 ms
66,032 KB
testcase_30 AC 373 ms
61,624 KB
testcase_31 AC 466 ms
81,936 KB
testcase_32 AC 398 ms
65,624 KB
testcase_33 AC 341 ms
56,872 KB
testcase_34 AC 407 ms
65,576 KB
testcase_35 AC 464 ms
79,872 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 518 ms
97,144 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 406 ms
65,448 KB
testcase_42 WA -
testcase_43 WA -
testcase_44 AC 380 ms
59,524 KB
testcase_45 WA -
testcase_46 AC 493 ms
97,064 KB
testcase_47 WA -
testcase_48 AC 506 ms
97,156 KB
testcase_49 AC 488 ms
97,144 KB
testcase_50 AC 255 ms
54,292 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