結果
問題 | No.1433 Two color sequence |
ユーザー | kichi2004_ |
提出日時 | 2021-03-19 22:19:13 |
言語 | Rust (1.77.0) |
結果 |
AC
|
実行時間 | 41 ms / 2,000 ms |
コード長 | 2,094 bytes |
コンパイル時間 | 1,891 ms |
コンパイル使用メモリ | 153,228 KB |
実行使用メモリ | 16,624 KB |
最終ジャッジ日時 | 2023-08-12 02:42:42 |
合計ジャッジ時間 | 4,265 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,380 KB |
testcase_01 | AC | 1 ms
4,380 KB |
testcase_02 | AC | 1 ms
4,380 KB |
testcase_03 | AC | 33 ms
15,864 KB |
testcase_04 | AC | 33 ms
15,888 KB |
testcase_05 | AC | 1 ms
4,376 KB |
testcase_06 | AC | 1 ms
4,376 KB |
testcase_07 | AC | 1 ms
4,376 KB |
testcase_08 | AC | 38 ms
15,860 KB |
testcase_09 | AC | 41 ms
15,424 KB |
testcase_10 | AC | 39 ms
14,964 KB |
testcase_11 | AC | 40 ms
15,032 KB |
testcase_12 | AC | 41 ms
15,420 KB |
testcase_13 | AC | 41 ms
15,432 KB |
testcase_14 | AC | 39 ms
15,676 KB |
testcase_15 | AC | 40 ms
15,724 KB |
testcase_16 | AC | 39 ms
15,724 KB |
testcase_17 | AC | 40 ms
15,712 KB |
testcase_18 | AC | 39 ms
15,712 KB |
testcase_19 | AC | 41 ms
15,724 KB |
testcase_20 | AC | 40 ms
15,740 KB |
testcase_21 | AC | 41 ms
16,624 KB |
testcase_22 | AC | 40 ms
15,736 KB |
testcase_23 | AC | 40 ms
15,724 KB |
ソースコード
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); }