結果

問題 No.1433 Two color sequence
ユーザー Masaki KitaguchiMasaki Kitaguchi
提出日時 2022-01-23 08:05:05
言語 Rust
(1.77.0)
結果
AC  
実行時間 19 ms / 2,000 ms
コード長 1,063 bytes
コンパイル時間 878 ms
コンパイル使用メモリ 149,292 KB
実行使用メモリ 9,416 KB
最終ジャッジ日時 2023-08-19 11:12:45
合計ジャッジ時間 4,530 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 9 ms
6,296 KB
testcase_04 AC 8 ms
6,240 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 17 ms
9,400 KB
testcase_09 AC 19 ms
9,404 KB
testcase_10 AC 18 ms
9,140 KB
testcase_11 AC 18 ms
9,136 KB
testcase_12 AC 18 ms
9,412 KB
testcase_13 AC 19 ms
9,356 KB
testcase_14 AC 18 ms
9,408 KB
testcase_15 AC 18 ms
9,364 KB
testcase_16 AC 18 ms
9,412 KB
testcase_17 AC 18 ms
9,416 KB
testcase_18 AC 18 ms
9,392 KB
testcase_19 AC 18 ms
9,400 KB
testcase_20 AC 17 ms
9,408 KB
testcase_21 AC 18 ms
9,412 KB
testcase_22 AC 18 ms
9,400 KB
testcase_23 AC 18 ms
9,360 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#[macro_export]
macro_rules! setup {
    { mut $input:ident: SplitWhitespace $(,)? } => {
        use std::io::Read;
        let mut buf = String::new();
        std::io::stdin().read_to_string(&mut buf).ok();
        let mut $input = buf.split_whitespace();
    };
}

#[macro_export]
macro_rules! parse_next {
    ($str_iter:expr) => {
        $str_iter.next().unwrap().parse().ok().unwrap()
    };
}

fn main() {
    setup! { mut input: SplitWhitespace };

    let n: usize = parse_next!(input);
    let s: String = parse_next!(input);
    let mut a: Vec<i64> = (0..n).map(|_| parse_next!(input)).collect();

    s.chars().enumerate().for_each(|(i, c)| match c {
        'R' => {
            a[i] = a[i];
        }
        'B' => {
            a[i] = -a[i];
        }
        _ => unreachable!(),
    });

    let mut b = vec![0; n + 1];
    for i in 0..n {
        b[i + 1] = b[i] + a[i];
    }

    let ans = (|| {
        let min = *b.iter().min().unwrap();
        let max = *b.iter().max().unwrap();
        max - min
    })();

    println!("{}", ans);
}
0