結果
問題 | No.1433 Two color sequence |
ユーザー | tonyu0 |
提出日時 | 2021-03-19 22:34:11 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 20 ms / 2,000 ms |
コード長 | 857 bytes |
コンパイル時間 | 13,287 ms |
コンパイル使用メモリ | 387,584 KB |
実行使用メモリ | 8,192 KB |
最終ジャッジ日時 | 2024-11-18 23:28:43 |
合計ジャッジ時間 | 15,093 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
use std::io::*;fn main() {let mut s: String = String::new();std::io::stdin().read_to_string(&mut s).ok();let mut itr = s.trim().split_whitespace();let n: usize = itr.next().unwrap().parse().unwrap();let s: Vec<char> = itr.next().unwrap().chars().collect();let mut a: Vec<i64> = (0..n).map(|_| itr.next().unwrap().parse().unwrap()).collect();let mut ans = 0;for i in 0..n {if s[i] == 'B' {a[i] *= -1;}}let mut b = a.clone();for i in 0..n {b[i] *= -1;}let mut now = 0;for i in 0..n {now = std::cmp::max(a[i], a[i] + now);ans = std::cmp::max(ans, now);}now = 0;for i in 0..n {now = std::cmp::max(b[i], b[i] + now);ans = std::cmp::max(ans, now);}println!("{}", ans);}