結果
問題 | No.1433 Two color sequence |
ユーザー |
![]() |
提出日時 | 2021-03-20 11:54:53 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 15 ms / 2,000 ms |
コード長 | 1,327 bytes |
コンパイル時間 | 13,874 ms |
コンパイル使用メモリ | 378,144 KB |
実行使用メモリ | 6,016 KB |
最終ジャッジ日時 | 2024-11-20 20:56:14 |
合計ジャッジ時間 | 16,827 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
#[allow(dead_code)]mod io {use std::str::{FromStr, SplitWhitespace};pub struct Scanner<'a>(pub SplitWhitespace<'a>);impl<'a> Scanner<'a> {pub fn next<T: FromStr>(&mut self) -> T {self.0.next().unwrap().parse().ok().unwrap()}}pub fn next<'a, T: FromStr, I: Iterator<Item = &'a str>>(iter: &mut I) -> T {iter.next().unwrap().parse().ok().unwrap()}pub fn vec<T, F: FnMut() -> T>(f: F, n: usize) -> Vec<T> {std::iter::repeat_with(f).take(n).collect()}}use std::io::Read;fn main() {let ref mut buf = String::new();std::io::stdin().read_to_string(buf).ok();let mut sc = io::Scanner(buf.split_whitespace());let n = sc.next::<usize>();let s = sc.next::<String>().into_bytes();let a = io::vec(|| sc.next::<i64>(), n);let mut ans = std::i64::MIN;let mut r_plus = 0;let mut b_plus = 0;for (s, a) in s.iter().zip(a.iter()) {if *s == b'R' {r_plus += a;b_plus -= a;} else {r_plus -= a;b_plus += a;}ans = ans.max(r_plus);ans = ans.max(b_plus);if r_plus < 0 {r_plus = 0;}if b_plus < 0 {b_plus = 0;}}println!("{}", ans);}