結果

問題 No.852 連続部分文字列
ユーザー pekempeypekempey
提出日時 2019-07-27 03:31:41
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 324 ms / 3,153 ms
コード長 1,076 bytes
コンパイル時間 13,315 ms
コンパイル使用メモリ 425,548 KB
実行使用メモリ 54,908 KB
最終ジャッジ日時 2023-08-13 02:46:09
合計ジャッジ時間 28,408 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 268 ms
52,416 KB
testcase_01 AC 270 ms
52,560 KB
testcase_02 AC 273 ms
52,624 KB
testcase_03 AC 274 ms
52,604 KB
testcase_04 AC 272 ms
52,640 KB
testcase_05 AC 271 ms
52,424 KB
testcase_06 AC 273 ms
52,564 KB
testcase_07 AC 276 ms
52,636 KB
testcase_08 AC 273 ms
52,664 KB
testcase_09 AC 269 ms
52,584 KB
testcase_10 AC 271 ms
52,644 KB
testcase_11 AC 276 ms
52,796 KB
testcase_12 AC 267 ms
52,824 KB
testcase_13 AC 289 ms
52,644 KB
testcase_14 AC 289 ms
52,740 KB
testcase_15 AC 287 ms
52,664 KB
testcase_16 AC 285 ms
52,676 KB
testcase_17 AC 287 ms
52,560 KB
testcase_18 AC 288 ms
52,764 KB
testcase_19 AC 271 ms
52,436 KB
testcase_20 AC 281 ms
52,636 KB
testcase_21 AC 285 ms
52,832 KB
testcase_22 AC 277 ms
52,940 KB
testcase_23 AC 286 ms
52,748 KB
testcase_24 AC 287 ms
52,548 KB
testcase_25 AC 289 ms
52,688 KB
testcase_26 AC 282 ms
52,724 KB
testcase_27 AC 283 ms
52,832 KB
testcase_28 AC 284 ms
52,556 KB
testcase_29 AC 285 ms
52,704 KB
testcase_30 AC 283 ms
52,660 KB
testcase_31 AC 290 ms
52,660 KB
testcase_32 AC 293 ms
52,720 KB
testcase_33 AC 324 ms
54,808 KB
testcase_34 AC 324 ms
54,908 KB
testcase_35 AC 320 ms
54,740 KB
testcase_36 AC 319 ms
54,884 KB
testcase_37 AC 317 ms
54,900 KB
testcase_38 AC 320 ms
54,804 KB
testcase_39 AC 318 ms
54,872 KB
testcase_40 AC 314 ms
54,744 KB
testcase_41 AC 319 ms
54,708 KB
testcase_42 AC 319 ms
54,880 KB
testcase_43 AC 319 ms
54,824 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