結果
問題 | No.1433 Two color sequence |
ユーザー |
|
提出日時 | 2021-04-08 23:53:05 |
言語 | Kotlin (2.1.0) |
結果 |
AC
|
実行時間 | 916 ms / 2,000 ms |
コード長 | 582 bytes |
コンパイル時間 | 12,713 ms |
コンパイル使用メモリ | 431,408 KB |
実行使用メモリ | 105,600 KB |
最終ジャッジ日時 | 2024-06-24 02:27:58 |
合計ジャッジ時間 | 32,562 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
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] * -1Lif(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)}