結果

問題 No.852 連続部分文字列
ユーザー rutilicusrutilicus
提出日時 2020-10-17 23:57:03
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 551 ms / 3,153 ms
コード長 890 bytes
コンパイル時間 16,806 ms
コンパイル使用メモリ 418,496 KB
実行使用メモリ 77,492 KB
最終ジャッジ日時 2023-09-28 08:44:01
合計ジャッジ時間 31,600 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 240 ms
52,840 KB
testcase_01 AC 241 ms
52,692 KB
testcase_02 AC 244 ms
52,824 KB
testcase_03 AC 244 ms
52,812 KB
testcase_04 AC 268 ms
52,816 KB
testcase_05 AC 245 ms
52,688 KB
testcase_06 AC 249 ms
52,752 KB
testcase_07 AC 250 ms
52,796 KB
testcase_08 AC 246 ms
52,768 KB
testcase_09 AC 249 ms
52,676 KB
testcase_10 AC 244 ms
52,812 KB
testcase_11 AC 241 ms
52,752 KB
testcase_12 AC 246 ms
52,740 KB
testcase_13 AC 276 ms
53,376 KB
testcase_14 AC 276 ms
53,000 KB
testcase_15 AC 282 ms
52,976 KB
testcase_16 AC 278 ms
52,952 KB
testcase_17 AC 286 ms
53,076 KB
testcase_18 AC 286 ms
53,136 KB
testcase_19 AC 254 ms
52,704 KB
testcase_20 AC 271 ms
52,936 KB
testcase_21 AC 291 ms
53,328 KB
testcase_22 AC 274 ms
53,000 KB
testcase_23 AC 295 ms
53,208 KB
testcase_24 AC 283 ms
53,212 KB
testcase_25 AC 288 ms
53,044 KB
testcase_26 AC 293 ms
52,976 KB
testcase_27 AC 284 ms
53,144 KB
testcase_28 AC 284 ms
53,300 KB
testcase_29 AC 348 ms
53,028 KB
testcase_30 AC 344 ms
52,924 KB
testcase_31 AC 366 ms
53,224 KB
testcase_32 AC 361 ms
53,092 KB
testcase_33 AC 551 ms
76,764 KB
testcase_34 AC 549 ms
76,832 KB
testcase_35 AC 482 ms
77,248 KB
testcase_36 AC 483 ms
77,188 KB
testcase_37 AC 483 ms
76,532 KB
testcase_38 AC 486 ms
76,632 KB
testcase_39 AC 485 ms
77,188 KB
testcase_40 AC 486 ms
77,492 KB
testcase_41 AC 482 ms
77,276 KB
testcase_42 AC 426 ms
76,572 KB
testcase_43 AC 437 ms
76,272 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:29:13: warning: 'appendln(Double): 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(cnt.toDouble() / allPat.toDouble())
            ^

ソースコード

diff #

fun main() {
    val builder = StringBuilder()

    val s = readInputLine()

    val posArr = Array('z' - 'a' + 1) { mutableListOf<Int>() }

    val allPat = s.length.toLong() * (s.length + 1).toLong() / 2L

    s.forEachIndexed { index, c ->
        posArr[c - 'a'].add(index)
    }

    var cnt = 0L

    for (pos in posArr) {
        var adder = allPat
        var prevIndex = -1
        for (i in pos) {
            // prevIndex + 1 ~ i - 1の範囲で組む部分文字列パターン数を除外
            adder -= (i - prevIndex - 1).toLong() * (i - prevIndex).toLong() / 2L
            prevIndex = i
        }
        adder -= (s.length - prevIndex - 1).toLong() * (s.length - prevIndex).toLong() / 2L

        cnt += adder
    }

    builder.appendln(cnt.toDouble() / allPat.toDouble())

    print(builder.toString())
}

fun readInputLine(): String {
    return readLine()!!
}
0