結果
問題 |
No.1053 ゲーミング棒
|
ユーザー |
![]() |
提出日時 | 2020-10-16 09:25:05 |
言語 | Kotlin (2.1.0) |
結果 |
AC
|
実行時間 | 568 ms / 2,000 ms |
コード長 | 1,150 bytes |
コンパイル時間 | 13,987 ms |
コンパイル使用メモリ | 436,936 KB |
実行使用メモリ | 67,096 KB |
最終ジャッジ日時 | 2024-07-20 20:21:30 |
合計ジャッジ時間 | 30,580 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 34 |
コンパイルメッセージ
Main.kt:49:13: warning: 'appendln(Int): kotlin.text.StringBuilder /* = java.lang.StringBuilder */' is deprecated. Use appendLine instead. Note that the new method always appends the line feed character '\n' regardless of the system line separator. builder.appendln(ans) ^
ソースコード
fun main() { val builder = StringBuilder() // 解説読んだ // 問題のシチュは環とみなせるっぽい // 異なる数字がある場合、左右端がその数字の場合のみ1回移動で連続とみなせる val n = readInputLine().toInt() val list = mutableListOf<Int>() var prev = -1 readInputLine().split(" ").map { (it.toInt() - 1).apply { if (this != prev) { if (prev != -1) { list.add(prev) } prev = this } } } list.add(prev) val cnt = IntArray(n) var ans = 0 for (l in list) { when(cnt[l]) { 0 -> cnt[l]++ 1 -> { if (list.first() != l || list.last() != l) { ans = -1 break } cnt[l]++ ans = 1 } else -> { ans = -1 break } } } builder.appendln(ans) print(builder.toString()) } fun readInputLine(): String { return readLine()!! }