結果

問題 No.150 "良問"(良問とは言っていない
ユーザー バカらっくバカらっく
提出日時 2021-11-10 10:35:25
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 332 ms / 5,000 ms
コード長 1,046 bytes
コンパイル時間 14,590 ms
コンパイル使用メモリ 454,980 KB
実行使用メモリ 59,144 KB
最終ジャッジ日時 2024-04-30 21:40:13
合計ジャッジ時間 17,769 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 316 ms
57,048 KB
testcase_01 AC 277 ms
56,944 KB
testcase_02 AC 276 ms
56,872 KB
testcase_03 AC 270 ms
56,816 KB
testcase_04 AC 271 ms
56,816 KB
testcase_05 AC 285 ms
56,908 KB
testcase_06 AC 332 ms
59,144 KB
testcase_07 AC 267 ms
56,816 KB
testcase_08 AC 267 ms
56,856 KB
testcase_09 AC 271 ms
56,964 KB
testcase_10 AC 301 ms
56,992 KB
testcase_11 AC 298 ms
57,048 KB
testcase_12 AC 293 ms
57,012 KB
testcase_13 AC 303 ms
57,056 KB
testcase_14 AC 309 ms
56,968 KB
testcase_15 AC 310 ms
57,120 KB
testcase_16 AC 275 ms
57,104 KB
testcase_17 AC 289 ms
57,000 KB
testcase_18 AC 312 ms
57,008 KB
testcase_19 AC 327 ms
57,188 KB
testcase_20 AC 325 ms
57,132 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:3:10: warning: parameter 'args' is never used
fun main(args: Array<String>) {
         ^

ソースコード

diff #

import java.lang.StringBuilder

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val ans = StringBuilder()
    for(i in 1..n) {
        ans.appendLine(solve(readLine()!!))
    }
    print(ans.toString())
}

fun solve(s:String):Int {
    val w1 = "good"
    val w2 = "problem"
    var w2Index:Int? = null
    var w2Count = 100
    var ans = s.length
    for(i in (0..(s.length-w1.length-w2.length))) {
        val w1Conv = diff(s.drop(i).take(w1.length), w1)
        if(w2Index?:0 >=i+w1.length) {
            ans = Math.min(ans, w1Conv + w2Count)
            continue
        }
        var convCount = 100
        for(j in (i+w1.length..s.length - w2.length)) {
            val tmp = diff(s.drop(j).take(w2.length), w2)
            if(convCount >= tmp) {
                w2Index = j
                w2Count = tmp
                convCount = tmp
            }
        }
        ans = Math.min(ans, w1Conv + w2Count)
    }
    return ans
}

fun diff(s1:String, s2:String):Int {
    return s1.indices.count { s1[it] != s2[it] }
}
0