結果
問題 | No.1208 anti primenumber game |
ユーザー |
![]() |
提出日時 | 2020-09-02 21:42:03 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 69 ms / 2,000 ms |
コード長 | 1,515 bytes |
コンパイル時間 | 14,353 ms |
コンパイル使用メモリ | 398,020 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-21 21:47:32 |
合計ジャッジ時間 | 17,953 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 44 |
ソースコード
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)};}macro_rules! chmin {($a:expr, $b:expr) => {$a = std::cmp::min($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 mut dp = vec![0, 0];for i in (0..n).rev() {let x = a[i];let mut nxt = vec![0, 0];nxt[0] = dp[1] + (x - m);nxt[1] = dp[0] - (x - m);if x >= 2 {chmax!(nxt[0], dp[0] + (x - 1) - (1 - m));chmin!(nxt[1], dp[1] - (x - 1) + (1 - m));}dp = nxt;}println!("{}", if dp[0] > 0 { "First" } else { "Second" });}