結果
| 問題 | No.204 ゴールデン・ウィーク(2) |
| コンテスト | |
| ユーザー |
rutilicus
|
| 提出日時 | 2020-10-16 01:18:33 |
| 言語 | Kotlin (2.3.20) |
| 結果 |
CE
(最新)
WA
(最初)
|
| 実行時間 | - |
| コード長 | 1,756 bytes |
| 記録 | |
| コンパイル時間 | 10,551 ms |
| コンパイル使用メモリ | 442,916 KB |
| 最終ジャッジ日時 | 2026-04-03 02:21:01 |
| 合計ジャッジ時間 | 16,551 ms |
|
ジャッジサーバーID (参考情報) |
judge4_1 / judge3_1 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
Main.kt:50: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(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
}
if (arr[i - 1].second >= d) {
if (arr[i - 1].second == d) {
ans = max(ans, p.second + d + arr[i - 2].second)
} else {
ans = max(ans, p.second + d)
}
}
if (arr[i + 1].second >= d) {
if (arr[i + 1].second == d) {
ans = max(ans, p.second + d + arr[i + 2].second)
} else {
ans = max(ans, p.second + d)
}
}
}
builder.appendln(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