結果
問題 | No.1208 anti primenumber game |
ユーザー | ikd |
提出日時 | 2020-09-02 21:16:32 |
言語 | Rust (1.83.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,640 bytes |
コンパイル時間 | 19,712 ms |
コンパイル使用メモリ | 381,380 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-21 21:22:54 |
合計ジャッジ時間 | 15,621 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 37 WA * 7 |
ソースコード
pub struct ProconReader<R: std::io::Read> { reader: R, } impl<R: std::io::Read> ProconReader<R> { pub fn new(reader: R) -> Self { Self { reader } } pub fn get<T: std::str::FromStr>(&mut self) -> T { use std::io::Read; let buf = self .reader .by_ref() .bytes() .map(|b| b.unwrap()) .skip_while(|&byte| byte == b' ' || byte == b'\n' || byte == b'\r') .take_while(|&byte| byte != b' ' && byte != b'\n' && byte != b'\r') .collect::<Vec<_>>(); std::str::from_utf8(&buf) .unwrap() .parse() .ok() .expect("Parse Error.") } } macro_rules! chmax { ($a:expr, $b:expr) => { $a = std::cmp::max($a, $b) }; } fn main() { let stdin = std::io::stdin(); let mut rd = ProconReader::new(stdin.lock()); let n: usize = rd.get(); let m: i64 = rd.get(); let a: Vec<i64> = (0..n).map(|_| rd.get()).collect(); let sum = a.iter().sum::<i64>() - m * n as i64; let inf = std::i64::MAX / 2; let mut dp = vec![-inf; 2]; dp[0] = 0; for x in a { let mut nxt = vec![-inf; 2]; if dp[1] != -inf { if x >= 2 { nxt[1] = dp[1] + 1 - m; } nxt[0] = dp[1]; } if dp[0] != inf { chmax!(nxt[1], dp[0] + x - m); if x >= 2 { chmax!(nxt[0], dp[0] + x - 1); } } dp = nxt; } let max = dp.iter().max().unwrap(); println!("{}", if *max > sum / 2 { "First" } else { "Second" }); }