結果
問題 |
No.1425 Yet Another Cyclic Shifts Sorting
|
ユーザー |
|
提出日時 | 2020-12-09 16:32:06 |
言語 | Kotlin (2.1.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,540 bytes |
コンパイル時間 | 13,201 ms |
コンパイル使用メモリ | 453,260 KB |
実行使用メモリ | 98,400 KB |
最終ジャッジ日時 | 2024-09-21 13:54:13 |
合計ジャッジ時間 | 35,125 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 46 WA * 2 |
ソースコード
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