結果

問題 No.1433 Two color sequence
ユーザー face4face4
提出日時 2021-04-08 23:53:05
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 908 ms / 2,000 ms
コード長 582 bytes
コンパイル時間 13,268 ms
コンパイル使用メモリ 421,288 KB
実行使用メモリ 82,152 KB
最終ジャッジ日時 2023-09-06 07:42:32
合計ジャッジ時間 34,219 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 298 ms
53,052 KB
testcase_01 AC 295 ms
53,056 KB
testcase_02 AC 295 ms
52,956 KB
testcase_03 AC 670 ms
65,288 KB
testcase_04 AC 672 ms
65,400 KB
testcase_05 AC 294 ms
53,012 KB
testcase_06 AC 297 ms
52,708 KB
testcase_07 AC 298 ms
53,016 KB
testcase_08 AC 881 ms
81,284 KB
testcase_09 AC 908 ms
81,644 KB
testcase_10 AC 867 ms
78,296 KB
testcase_11 AC 865 ms
78,288 KB
testcase_12 AC 899 ms
81,568 KB
testcase_13 AC 892 ms
82,152 KB
testcase_14 AC 882 ms
81,708 KB
testcase_15 AC 897 ms
81,400 KB
testcase_16 AC 889 ms
81,816 KB
testcase_17 AC 883 ms
81,824 KB
testcase_18 AC 884 ms
82,036 KB
testcase_19 AC 894 ms
81,956 KB
testcase_20 AC 885 ms
81,784 KB
testcase_21 AC 880 ms
81,476 KB
testcase_22 AC 897 ms
81,436 KB
testcase_23 AC 876 ms
81,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

fun main(){
    val n = readLine()!!.toInt()
    val s = readLine()!!
    val a = mutableListOf<Long>()
    a += readLine()!!.split(" ").map{it.toLong()}
    for(i in 0..n-1){
        if(s[i] == 'R')   a[i] = a[i] * -1L
        if(i > 0)   a[i] += a[i-1]
    }
    var answer = Math.abs(a[0])
    var befmin = Math.min(0, a[0])
    var befmax = Math.max(0, a[0])
    for(i in 1..n-1){
        answer = Math.max(answer, Math.max(Math.abs(befmin-a[i]), Math.abs(befmax-a[i])))
        befmin = Math.min(befmin, a[i])
        befmax = Math.max(befmax, a[i])
    }
    println(answer)
}
0