結果
問題 |
No.1425 Yet Another Cyclic Shifts Sorting
|
ユーザー |
|
提出日時 | 2020-12-09 17:01:45 |
言語 | Kotlin (2.1.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,085 bytes |
コンパイル時間 | 12,618 ms |
コンパイル使用メモリ | 435,156 KB |
実行使用メモリ | 86,544 KB |
最終ジャッジ日時 | 2024-09-21 13:56:52 |
合計ジャッジ時間 | 27,551 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 24 TLE * 1 -- * 23 |
ソースコード
import java.io.PrintWriter import java.util.* import kotlin.math.* fun PrintWriter.solve() { val n = nextInt() val a = Array(n) { nextInt() } if (isSorted(a)) { println(0) return } for (i in 1..n) { for (j in 1 until i) { val b = a.copyOf() for (k in 0 until i) { b[k] = a[(j + k) % i] } if (isSorted(b)) { println(1) return } } } println(2) } fun isSorted(a: Array<Int>): Boolean { return (0 until a.count() - 1).all { a[it] <= a[it + 1] } } 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