結果
| 問題 |
No.1433 Two color sequence
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-01-23 08:05:05 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 18 ms / 2,000 ms |
| コード長 | 1,063 bytes |
| コンパイル時間 | 12,540 ms |
| コンパイル使用メモリ | 392,028 KB |
| 実行使用メモリ | 7,552 KB |
| 最終ジャッジ日時 | 2024-11-29 03:19:45 |
| 合計ジャッジ時間 | 15,110 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 |
ソースコード
#[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);
}