結果

問題 No.1433 Two color sequence
ユーザー tonyu0tonyu0
提出日時 2021-03-19 22:34:11
言語 Rust
(1.77.0)
結果
AC  
実行時間 18 ms / 2,000 ms
コード長 857 bytes
コンパイル時間 11,349 ms
コンパイル使用メモリ 382,608 KB
実行使用メモリ 8,192 KB
最終ジャッジ日時 2024-04-29 17:43:44
合計ジャッジ時間 13,086 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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