結果
| 問題 |
No.204 ゴールデン・ウィーク(2)
|
| コンテスト | |
| ユーザー |
rutilicus
|
| 提出日時 | 2020-10-16 01:18:33 |
| 言語 | Kotlin (2.1.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,756 bytes |
| コンパイル時間 | 16,354 ms |
| コンパイル使用メモリ | 444,760 KB |
| 実行使用メモリ | 51,836 KB |
| 最終ジャッジ日時 | 2024-07-20 20:13:27 |
| 合計ジャッジ時間 | 33,417 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 39 WA * 7 |
コンパイルメッセージ
Main.kt:50: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)
^
ソースコード
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