結果

問題 No.672 最長AB列
ユーザー 💕💖💞💕💖💞
提出日時 2018-06-07 01:37:39
言語 Kotlin
(1.9.10)
結果
AC  
実行時間 716 ms / 2,000 ms
コード長 558 bytes
コンパイル時間 13,040 ms
コンパイル使用メモリ 426,520 KB
実行使用メモリ 86,020 KB
最終ジャッジ日時 2023-08-12 23:52:22
合計ジャッジ時間 23,176 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 302 ms
53,008 KB
testcase_01 AC 298 ms
53,048 KB
testcase_02 AC 298 ms
53,136 KB
testcase_03 AC 300 ms
54,644 KB
testcase_04 AC 302 ms
52,992 KB
testcase_05 AC 302 ms
52,776 KB
testcase_06 AC 299 ms
52,780 KB
testcase_07 AC 299 ms
53,024 KB
testcase_08 AC 303 ms
52,852 KB
testcase_09 AC 705 ms
86,020 KB
testcase_10 AC 704 ms
77,856 KB
testcase_11 AC 716 ms
77,448 KB
testcase_12 AC 558 ms
59,280 KB
testcase_13 AC 545 ms
58,708 KB
testcase_14 AC 546 ms
61,044 KB
testcase_15 AC 563 ms
59,120 KB
testcase_16 AC 585 ms
59,156 KB
testcase_17 AC 653 ms
71,556 KB
testcase_18 AC 518 ms
59,024 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:1:10: warning: parameter 'args' is never used
fun main(args:Array<String>) {
         ^
Main.kt:22:10: warning: unnecessary safe call on a non-null receiver of type Int
  }.max()?.let {
         ^

ソースコード

diff #

fun main(args:Array<String>) {
  val inputs = readLine()!!.toList().map {
    when {
      it == 'A' -> 1
      else -> -1
    }
  }
  // scanner
  val m = mutableMapOf<Int, MutableList<Int>>( 0 to mutableListOf(-1, -1, -1) )
  var s = 0
  inputs.mapIndexed { index, it ->
    s += it
    if( m.get(s) == null ) {
      m[s] = mutableListOf(index, -1, -1)
    } else {
      m[s]!![1] = index
      m[s]!![2] = index - m[s]!![0]
    }
  }
  m.toList().map {
    it.second[2]
  }.max()?.let {
    if( it < 0 ) 0
    else it
  }.run(::println)
  //println(m)
}
0