結果

問題 No.852 連続部分文字列
ユーザー pekempeypekempey
提出日時 2019-07-27 03:31:41
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 349 ms / 3,153 ms
コード長 1,076 bytes
コンパイル時間 12,511 ms
コンパイル使用メモリ 444,504 KB
実行使用メモリ 62,700 KB
最終ジャッジ日時 2024-11-20 19:09:25
合計ジャッジ時間 28,114 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 294 ms
60,332 KB
testcase_01 AC 293 ms
60,436 KB
testcase_02 AC 295 ms
60,360 KB
testcase_03 AC 293 ms
60,452 KB
testcase_04 AC 291 ms
60,220 KB
testcase_05 AC 296 ms
60,356 KB
testcase_06 AC 296 ms
60,276 KB
testcase_07 AC 293 ms
60,356 KB
testcase_08 AC 292 ms
60,436 KB
testcase_09 AC 296 ms
60,460 KB
testcase_10 AC 298 ms
60,356 KB
testcase_11 AC 299 ms
60,364 KB
testcase_12 AC 298 ms
60,452 KB
testcase_13 AC 317 ms
60,352 KB
testcase_14 AC 311 ms
60,344 KB
testcase_15 AC 317 ms
60,364 KB
testcase_16 AC 311 ms
60,500 KB
testcase_17 AC 312 ms
60,504 KB
testcase_18 AC 318 ms
60,336 KB
testcase_19 AC 298 ms
60,332 KB
testcase_20 AC 311 ms
60,480 KB
testcase_21 AC 315 ms
60,452 KB
testcase_22 AC 313 ms
60,372 KB
testcase_23 AC 311 ms
60,344 KB
testcase_24 AC 320 ms
60,516 KB
testcase_25 AC 309 ms
60,348 KB
testcase_26 AC 317 ms
60,336 KB
testcase_27 AC 313 ms
60,376 KB
testcase_28 AC 315 ms
60,352 KB
testcase_29 AC 318 ms
60,380 KB
testcase_30 AC 314 ms
60,372 KB
testcase_31 AC 316 ms
60,504 KB
testcase_32 AC 320 ms
60,388 KB
testcase_33 AC 346 ms
62,460 KB
testcase_34 AC 344 ms
62,700 KB
testcase_35 AC 349 ms
62,592 KB
testcase_36 AC 341 ms
62,652 KB
testcase_37 AC 344 ms
62,564 KB
testcase_38 AC 342 ms
62,664 KB
testcase_39 AC 341 ms
62,536 KB
testcase_40 AC 337 ms
62,640 KB
testcase_41 AC 343 ms
62,528 KB
testcase_42 AC 338 ms
62,528 KB
testcase_43 AC 342 ms
62,688 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:1:10: warning: parameter 'args' is never used
fun main(args: Array<String>) {
         ^
Main.kt:41:16: warning: 'toByte(): Byte' is deprecated. Conversion of Char to Number is deprecated. Use Char.code property instead.
    while ('0'.toByte() > peek()) next()
               ^
Main.kt:42:16: warning: 'toByte(): Byte' is deprecated. Conversion of Char to Number is deprecated. Use Char.code property instead.
    while ('0'.toByte() <= peek()) {
               ^
Main.kt:43:25: warning: 'toChar(): Char' is deprecated. Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.
      ans.append(peek().toChar())
                        ^
Main.kt:51:16: warning: 'toByte(): Byte' is deprecated. Conversion of Char to Number is deprecated. Use Char.code property instead.
    while ('0'.toByte() > peek()) next()
               ^
Main.kt:52:16: warning: 'toByte(): Byte' is deprecated. Conversion of Char to Number is deprecated. Use Char.code property instead.
    while ('0'.toByte() <= peek()) {
               ^
Main.kt:53:38: warning: 'toLong(): Long' is deprecated. Conversion of Char to Number is deprecated. Use Char.code property instead.
      ans = ans * 10 + (peek() - '0'.toLong())
                                     ^

ソースコード

diff #

fun main(args: Array<String>) {
  val rd = Reader()
  val S = rd.string()
  val N = S.length
  val mae = IntArray(26, {-1})
  var kotae = 0L
  for (i in 0..N-1) {
    kotae += (i - mae[S[i] - 'a']).toLong() * (N - i)
    mae[S[i] - 'a'] = i
  }
  println(2.0 * kotae / N / (N + 1))
}

class Reader {
  var buf: ByteArray = ByteArray(5000000)
  var k: Int = 0
  var n: Int = 0

  init {
    check()
  }

  private fun check() {
    if (k == n) {
      n = System.`in`.read(buf)
      k = 0
    }
  }

  private fun peek(): Byte {
    return buf[k]
  }

  private fun next() {
    k++
    check()
  }

  fun string(): String {
    var ans = StringBuilder()
    while ('0'.toByte() > peek()) next()
    while ('0'.toByte() <= peek()) {
      ans.append(peek().toChar())
      next()
    }
    return ans.toString()
  }

  fun long(): Long {
    var ans: Long = 0
    while ('0'.toByte() > peek()) next()
    while ('0'.toByte() <= peek()) {
      ans = ans * 10 + (peek() - '0'.toLong())
      next() 
    }
    return ans
  }

  fun int(): Int {
    return long().toInt()
  }
}
0