結果
問題 | No.672 最長AB列 |
ユーザー | 💕💖💞 |
提出日時 | 2018-06-07 01:23:36 |
言語 | Kotlin (1.9.23) |
結果 |
RE
|
実行時間 | - |
コード長 | 877 bytes |
コンパイル時間 | 14,787 ms |
コンパイル使用メモリ | 450,008 KB |
実行使用メモリ | 102,836 KB |
最終ジャッジ日時 | 2024-04-30 18:44:40 |
合計ジャッジ時間 | 17,987 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 285 ms
60,396 KB |
testcase_01 | AC | 281 ms
94,900 KB |
testcase_02 | RE | - |
testcase_03 | RE | - |
testcase_04 | AC | 279 ms
57,016 KB |
testcase_05 | AC | 276 ms
56,932 KB |
testcase_06 | AC | 273 ms
57,176 KB |
testcase_07 | AC | 295 ms
56,984 KB |
testcase_08 | AC | 291 ms
56,956 KB |
testcase_09 | RE | - |
testcase_10 | TLE | - |
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:22:10: warning: variable 'k' is never used val (k,v) = it ^ Main.kt:25:12: warning: variable 'v' is never used val (k,v) = it ^ Main.kt:46:12: warning: unnecessary safe call on a non-null receiver of type Int ans.max()?.let(::println) ?: println(0) ^ Main.kt:46:29: warning: elvis operator (?:) always returns the left operand of non-nullable type Unit ans.max()?.let(::println) ?: println(0) ^
ソースコード
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) val m = mutableMapOf<Int, Int>( 0 to 1 ) inputs.map { s += it if( m.get(s) == null ) { m[s] = 1 } else { m[s] = m[s]!! + 1 } tri.add(s) } val pats = m.toList().filter { val (k,v) = it v >= 2 }.map { val (k,v) = it k } 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) }