結果

問題 No.1433 Two color sequence
ユーザー StrorkisStrorkis
提出日時 2021-03-20 11:54:53
言語 Rust
(1.77.0)
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 1,327 bytes
コンパイル時間 12,150 ms
コンパイル使用メモリ 377,736 KB
実行使用メモリ 6,016 KB
最終ジャッジ日時 2024-04-30 22:36:01
合計ジャッジ時間 14,203 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 7 ms
5,376 KB
testcase_04 AC 8 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 15 ms
6,016 KB
testcase_09 AC 15 ms
5,888 KB
testcase_10 AC 15 ms
5,760 KB
testcase_11 AC 13 ms
5,888 KB
testcase_12 AC 13 ms
5,888 KB
testcase_13 AC 12 ms
5,888 KB
testcase_14 AC 13 ms
5,888 KB
testcase_15 AC 13 ms
5,888 KB
testcase_16 AC 12 ms
6,016 KB
testcase_17 AC 12 ms
5,888 KB
testcase_18 AC 12 ms
6,016 KB
testcase_19 AC 12 ms
6,016 KB
testcase_20 AC 13 ms
5,888 KB
testcase_21 AC 13 ms
5,888 KB
testcase_22 AC 13 ms
5,888 KB
testcase_23 AC 13 ms
5,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#[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);
}
0