結果
| 問題 |
No.852 連続部分文字列
|
| コンテスト | |
| ユーザー |
rutilicus
|
| 提出日時 | 2020-10-17 23:57:03 |
| 言語 | Kotlin (2.1.0) |
| 結果 |
AC
|
| 実行時間 | 644 ms / 3,153 ms |
| コード長 | 890 bytes |
| コンパイル時間 | 15,770 ms |
| コンパイル使用メモリ | 439,592 KB |
| 実行使用メモリ | 100,708 KB |
| 最終ジャッジ日時 | 2024-07-21 03:14:17 |
| 合計ジャッジ時間 | 35,871 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 41 |
コンパイルメッセージ
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())
^
ソースコード
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()!!
}
rutilicus