結果
問題 | No.2622 Dam |
ユーザー | naut3 |
提出日時 | 2024-02-09 22:12:51 |
言語 | Rust (1.77.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,883 bytes |
コンパイル時間 | 11,127 ms |
コンパイル使用メモリ | 406,068 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-09-28 15:28:41 |
合計ジャッジ時間 | 11,941 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,816 KB |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | AC | 1 ms
6,816 KB |
testcase_04 | AC | 2 ms
6,820 KB |
testcase_05 | AC | 1 ms
6,820 KB |
ソースコード
#![allow(non_snake_case, unused_imports, unused_must_use)] use std::io::{self, prelude::*, BufWriter, StdinLock, StdoutLock}; use std::str; fn main() { let (stdin, stdout) = (io::stdin(), io::stdout()); let mut scan = Scanner::new(stdin.lock()); let mut out = io::BufWriter::new(stdout.lock()); macro_rules! input { ($T: ty) => { scan.token::<$T>() }; ($T: ty, $N: expr) => { (0..$N).map(|_| scan.token::<$T>()).collect::<Vec<_>>() }; } let t = input!(usize); for _ in 0..t { solve(&mut scan, &mut out); } } fn solve(scan: &mut Scanner<StdinLock>, out: &mut BufWriter<StdoutLock>) { macro_rules! input { ($T: ty) => { scan.token::<$T>() }; ($T: ty, $N: expr) => { (0..$N).map(|_| scan.token::<$T>()).collect::<Vec<_>>() }; } let V = input!(isize); let X = input!(isize); let F0 = input!(isize); let Fi = input!(isize); let Q = input!(isize); let R = input!(isize); let mut now = X; // R now += (Fi - F0) * R; if now <= 0 { writeln!(out, "Zero"); return; } else if now >= V { writeln!(out, "Overflow"); return; } // Q now -= (Q - R) * F0; let rep_start = now; if now <= 0 { writeln!(out, "Zero"); return; } else if now >= V { writeln!(out, "Overflow"); return; } // Q + R now += (Fi - F0) * R; if now <= 0 { writeln!(out, "Zero"); return; } else if now >= V { writeln!(out, "Overflow"); return; } // 2 * Q now -= (Q - R) * F0; if now <= 0 { writeln!(out, "Zero"); return; } else if now >= V { writeln!(out, "Overflow"); return; } let diff = now - rep_start; if diff < 0 { writeln!(out, "Zero"); } else if diff == 0 { writeln!(out, "Safe"); } else { writeln!(out, "Overflow"); } } struct Scanner<R> { reader: R, buf_str: Vec<u8>, buf_iter: str::SplitWhitespace<'static>, } impl<R: BufRead> Scanner<R> { fn new(reader: R) -> Self { Self { reader, buf_str: vec![], buf_iter: "".split_whitespace(), } } fn token<T: str::FromStr>(&mut self) -> T { loop { if let Some(token) = self.buf_iter.next() { return token.parse().ok().expect("Failed parse"); } self.buf_str.clear(); self.reader .read_until(b'\n', &mut self.buf_str) .expect("Failed read"); self.buf_iter = unsafe { let slice = str::from_utf8_unchecked(&self.buf_str); std::mem::transmute(slice.split_whitespace()) } } } }