結果
| 問題 |
No.204 ゴールデン・ウィーク(2)
|
| コンテスト | |
| ユーザー |
rutilicus
|
| 提出日時 | 2020-10-16 01:26:22 |
| 言語 | Kotlin (2.1.0) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,642 bytes |
| コンパイル時間 | 12,685 ms |
| コンパイル使用メモリ | 420,472 KB |
| 最終ジャッジ日時 | 2025-01-18 22:13:42 |
| 合計ジャッジ時間 | 13,491 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
Main.kt:42:13: error: 'fun StringBuilder.appendln(value: Int): 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(max(d, ans))
^^^^^^^^
ソースコード
import kotlin.math.max
fun main() {
val builder = StringBuilder()
val d = readInputLine().toInt()
val c = readInputLine() + readInputLine()
val runLength = runLength(c).toMutableList()
if (runLength[0].first == 'x') {
runLength[0] = runLength[0].copy(second = 15)
} else {
runLength.add(0, Pair('x', 15))
}
if (runLength[runLength.lastIndex].first == 'x') {
runLength[runLength.lastIndex] = runLength[runLength.lastIndex].copy(second = 15)
} else {
runLength.add(Pair('x', 15))
}
var ans = 0
val arr = runLength.toTypedArray()
for ((i, p) in arr.withIndex()) {
if (p.first != 'o') {
continue
}
ans = max(ans, when(arr[i - 1].second - d) {
in Int.MIN_VALUE..0 -> p.second + arr[i - 1].second + arr[i - 2].second
else -> p.second + d } )
ans = max(ans, when(arr[i + 1].second - d) {
in Int.MIN_VALUE..0 -> p.second + arr[i + 1].second + arr[i + 2].second
else -> p.second + d } )
}
builder.appendln(max(d, ans))
print(builder.toString())
}
fun readInputLine(): String {
return readLine()!!
}
fun runLength(s: String): List<Pair<Char, Int>> {
val ret = mutableListOf<Pair<Char, Int>>()
if (s.isNotEmpty()) {
var prev = s[0]
var cnt = 0
for (c in s) {
if (c == prev) {
cnt++
} else {
ret.add(Pair(prev, cnt))
prev = c
cnt = 1
}
}
ret.add(Pair(prev, cnt))
}
return ret.toList()
}
rutilicus