結果
| 問題 | 
                            No.1425 Yet Another Cyclic Shifts Sorting
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2020-12-29 06:04:50 | 
| 言語 | Kotlin  (2.1.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,537 bytes | 
| コンパイル時間 | 14,881 ms | 
| コンパイル使用メモリ | 440,776 KB | 
| 実行使用メモリ | 92,412 KB | 
| 最終ジャッジ日時 | 2024-10-04 17:26:03 | 
| 合計ジャッジ時間 | 35,279 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 WA * 1 | 
| other | AC * 35 WA * 13 | 
ソースコード
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]) {
            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