結果

問題 No.672 最長AB列
コンテスト
ユーザー 💕💖💞
提出日時 2018-06-07 01:37:39
言語 Kotlin
(2.3.20)
コンパイル:
kotlinc _filename_ -include-runtime -d main.jar
実行:
kotlin main.jar
結果
AC  
実行時間 484 ms / 2,000 ms
コード長 558 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 9,475 ms
コンパイル使用メモリ 478,336 KB
実行使用メモリ 103,628 KB
最終ジャッジ日時 2026-05-14 19:11:46
合計ジャッジ時間 15,841 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:22:10: warning: unnecessary safe call on a non-null receiver of type 'Int'.
  }.max()?.let {
         ^^

ソースコード

diff #
raw source code

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