結果
| 問題 |
No.1053 ゲーミング棒
|
| コンテスト | |
| ユーザー |
rutilicus
|
| 提出日時 | 2020-10-16 09:27:19 |
| 言語 | Kotlin (2.1.0) |
| 結果 |
AC
|
| 実行時間 | 459 ms / 2,000 ms |
| コード長 | 1,169 bytes |
| コンパイル時間 | 14,543 ms |
| コンパイル使用メモリ | 434,956 KB |
| 実行使用メモリ | 67,156 KB |
| 最終ジャッジ日時 | 2024-07-20 20:22:02 |
| 合計ジャッジ時間 | 26,599 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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
check@ for (l in list) {
when(cnt[l]) {
0 -> cnt[l]++
1 -> {
if (list.first() != l || list.last() != l) {
ans = -1
break@check
}
cnt[l]++
ans = 1
}
else -> {
ans = -1
break@check
}
}
}
builder.appendln(ans)
print(builder.toString())
}
fun readInputLine(): String {
return readLine()!!
}
rutilicus