結果
| 問題 |
No.1433 Two color sequence
|
| ユーザー |
kichi2004_
|
| 提出日時 | 2021-03-19 22:19:13 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 38 ms / 2,000 ms |
| コード長 | 2,094 bytes |
| コンパイル時間 | 11,476 ms |
| コンパイル使用メモリ | 388,204 KB |
| 実行使用メモリ | 16,560 KB |
| 最終ジャッジ日時 | 2024-11-18 23:00:56 |
| 合計ジャッジ時間 | 13,480 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 |
ソースコード
use std::str::FromStr;
use std::io::{BufRead, stdin, Stdin};
use std::collections::{VecDeque};
struct Scanner {
sep: char,
inputs: VecDeque<String>,
cin: Stdin,
}
#[allow(unused)]
impl Scanner {
pub fn new(ch: char) -> Scanner {
Scanner {
sep: ch,
inputs: VecDeque::new(),
cin: stdin(),
}
}
pub fn read<T: FromStr>(&mut self) -> T {
let mut tries = 0;
while bool::from(self.inputs.is_empty()) {
if tries == 3 {
panic!("3 Blank lines found.");
}
let cin_base = &mut self.cin;
let cin = &mut cin_base.lock();
let mut str: String = String::new();
cin.read_line(&mut str).unwrap();
for s in str.trim_end().split(self.sep) {
&self.inputs.push_back(String::from(s));
}
tries += 1;
}
let s: String = String::from(&self.inputs.pop_front().unwrap());
s.parse::<T>().ok()
.expect("Failed to parse token.")
}
pub fn read_i32(&mut self) -> i32 { self.read() }
pub fn read_i64(&mut self) -> i32 { self.read() }
pub fn read_usize(&mut self) -> usize { self.read() }
pub fn read_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
(0..n).map(|_| self.read()).collect::<Vec<_>>()
}
}
fn main() {
let mut sc = Scanner::new(' ');
let n = sc.read_usize();
let s = sc.read::<String>().chars().collect::<Vec<char>>();
let a = sc.read_vec::<i64>(n);
let mut score = vec![0i64; n];
score[0] = if s[0] == 'R' { a[0] } else { -a[0] };
for i in 1..n {
score[i] = score[i - 1] + if s[i] == 'R' { a[i] } else { -a[i] };
}
let mut current_min = 0i64;
let mut current_max = 0i64;
let mut ans = 0;
for i in 0..n {
ans = ans.max(&score[i] - current_min).max((&score[i] - current_max).abs());
// eprintln!("{}", nas);
current_max = current_max.max(score[i]);
current_min = current_min.min(score[i]);
}
println!("{}", ans);
}
kichi2004_