結果
問題 | No.2691 Longest Infection Sequence |
ユーザー |
|
提出日時 | 2024-03-23 16:09:30 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 1 ms / 2,000 ms |
コード長 | 1,643 bytes |
コンパイル時間 | 14,333 ms |
コンパイル使用メモリ | 382,580 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-09-30 13:31:05 |
合計ジャッジ時間 | 14,068 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 14 |
ソースコード
fn main() {let mut sc = Scanner::new(std::io::stdin().lock(), 20);let a: u32 = sc.next();let b: u32 = sc.next();let o: u32 = sc.next();let w: u32 = sc.next();let ans = solve(a, b, o, w);println!("{ans}");}fn solve(a: u32, b: u32, o: u32, w: u32) -> u32 {o + a.max(b) + w}struct Scanner<R: std::io::BufRead> {reader: R,buf: Vec<u8>,pos: usize,}impl<R: std::io::BufRead> Scanner<R> {fn new(reader: R, capacity: usize) -> Self {Scanner {reader,buf: Vec::with_capacity(capacity),pos: 0,}}fn next<T: std::str::FromStr>(&mut self) -> TwhereT::Err: std::fmt::Debug,{if self.buf.is_empty() {self.read_next_line();}let mut start = None;loop {if self.pos == self.buf.len() {break;}match (self.buf[self.pos], start.is_some()) {(b' ', true) | (b'\n', true) => break,(_, true) | (b' ', false) => self.pos += 1,(b'\n', false) => self.read_next_line(),(_, false) => start = Some(self.pos),}}let elem = unsafe { std::str::from_utf8_unchecked(&self.buf[start.unwrap()..self.pos]) };elem.parse().unwrap_or_else(|_| panic!("{}", format!("failed parsing: {}", elem)))}fn read_next_line(&mut self) {self.pos = 0;self.buf.clear();if self.reader.read_until(b'\n', &mut self.buf).unwrap() == 0 {panic!("Reached EOF");}}}