結果

問題 No.852 連続部分文字列
ユーザー pekempeypekempey
提出日時 2019-07-27 03:27:30
言語 Kotlin
(1.9.23)
結果
WA  
実行時間 -
コード長 1,038 bytes
コンパイル時間 14,205 ms
コンパイル使用メモリ 424,600 KB
実行使用メモリ 86,296 KB
最終ジャッジ日時 2023-08-13 02:45:36
合計ジャッジ時間 30,960 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 268 ms
55,724 KB
testcase_01 AC 275 ms
86,296 KB
testcase_02 AC 269 ms
52,792 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 WA -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 TLE -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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:21: warning: 'toChar(): Char' is deprecated. Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.
      ans += 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[i]).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 = ""
    while ('0'.toByte() > peek()) next()
    while ('0'.toByte() <= peek()) {
      ans += peek().toChar()
      next()
    }
    return ans
  }

  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