結果
| 問題 | No.672 最長AB列 | 
| コンテスト | |
| ユーザー |  💕💖💞 | 
| 提出日時 | 2018-06-07 01:37:39 | 
| 言語 | Kotlin (2.1.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 730 ms / 2,000 ms | 
| コード長 | 558 bytes | 
| コンパイル時間 | 12,151 ms | 
| コンパイル使用メモリ | 435,292 KB | 
| 実行使用メモリ | 102,744 KB | 
| 最終ジャッジ日時 | 2024-11-20 16:14:16 | 
| 合計ジャッジ時間 | 22,435 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 16 | 
コンパイルメッセージ
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 {
         ^
            
            ソースコード
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)
}
            
            
            
        