結果

問題 No.1433 Two color sequence
ユーザー tonyu0tonyu0
提出日時 2021-03-19 22:34:11
言語 Rust
(1.72.1)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 857 bytes
コンパイル時間 1,157 ms
コンパイル使用メモリ 148,172 KB
実行使用メモリ 10,016 KB
最終ジャッジ日時 2023-08-12 03:08:04
合計ジャッジ時間 3,114 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 10 ms
6,944 KB
testcase_04 AC 10 ms
6,848 KB
testcase_05 AC 1 ms
4,388 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 19 ms
10,008 KB
testcase_09 AC 19 ms
9,992 KB
testcase_10 AC 18 ms
9,724 KB
testcase_11 AC 20 ms
9,720 KB
testcase_12 AC 19 ms
9,932 KB
testcase_13 AC 20 ms
10,016 KB
testcase_14 AC 19 ms
9,984 KB
testcase_15 AC 18 ms
10,004 KB
testcase_16 AC 20 ms
9,996 KB
testcase_17 AC 19 ms
10,008 KB
testcase_18 AC 18 ms
9,996 KB
testcase_19 AC 19 ms
10,004 KB
testcase_20 AC 19 ms
9,984 KB
testcase_21 AC 19 ms
10,004 KB
testcase_22 AC 19 ms
9,984 KB
testcase_23 AC 19 ms
10,012 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