結果

問題 No.672 最長AB列
ユーザー 💕💖💞💕💖💞
提出日時 2018-06-07 01:11:18
言語 Kotlin
(1.9.23)
結果
TLE  
実行時間 -
コード長 670 bytes
コンパイル時間 14,108 ms
コンパイル使用メモリ 446,936 KB
実行使用メモリ 95,060 KB
最終ジャッジ日時 2024-04-30 18:44:15
合計ジャッジ時間 16,944 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 275 ms
60,464 KB
testcase_01 AC 269 ms
95,060 KB
testcase_02 AC 273 ms
63,988 KB
testcase_03 AC 271 ms
57,060 KB
testcase_04 AC 275 ms
57,028 KB
testcase_05 AC 272 ms
57,016 KB
testcase_06 AC 268 ms
56,984 KB
testcase_07 AC 271 ms
56,968 KB
testcase_08 AC 273 ms
56,924 KB
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:1:10: warning: parameter 'args' is never used
fun main(args:Array<String>) {
         ^
Main.kt:34:12: warning: unnecessary safe call on a non-null receiver of type Int
  ans.max()?.let(::println) ?: println(0)
           ^
Main.kt:34:29: warning: elvis operator (?:) always returns the left operand of non-nullable type Unit
  ans.max()?.let(::println) ?: println(0)
                            ^

ソースコード

diff #

fun main(args:Array<String>) {
  val inputs = readLine()!!.toList().map {
    when {
      it == 'A' -> 1
      else -> -1
    }
  }
  // scanner
  var s = 0
  val tri = mutableListOf<Int>(0)
  inputs.map {
    s += it
    tri.add(s)
  }
  val pats = tri.toSet()
  val ans = mutableListOf<Int>()
  pats.map { pat ->
    var start = -1
    for( _start in (0..tri.size-1) ) {
      if( tri[_start] == pat ) {
        start = _start
        break
      }
    }
    var end = -1
    for( _end in (tri.size-1 downTo 0) ) {
      if( tri[_end] == pat ) {
        end = _end
        break
      }
    }
    ans.add( end - start )
  }
  ans.max()?.let(::println) ?: println(0)
}
0