結果

問題 No.1208 anti primenumber game
ユーザー ikdikd
提出日時 2020-09-02 21:42:03
言語 Rust
(1.77.0)
結果
AC  
実行時間 70 ms / 2,000 ms
コード長 1,515 bytes
コンパイル時間 1,006 ms
コンパイル使用メモリ 151,748 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-14 03:43:46
合計ジャッジ時間 4,318 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 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 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,384 KB
testcase_14 AC 1 ms
4,384 KB
testcase_15 AC 19 ms
4,380 KB
testcase_16 AC 20 ms
4,384 KB
testcase_17 AC 20 ms
4,380 KB
testcase_18 AC 20 ms
4,380 KB
testcase_19 AC 20 ms
4,384 KB
testcase_20 AC 20 ms
4,380 KB
testcase_21 AC 21 ms
4,380 KB
testcase_22 AC 21 ms
4,380 KB
testcase_23 AC 21 ms
4,376 KB
testcase_24 AC 70 ms
4,380 KB
testcase_25 AC 70 ms
4,376 KB
testcase_26 AC 66 ms
4,380 KB
testcase_27 AC 66 ms
4,380 KB
testcase_28 AC 66 ms
4,380 KB
testcase_29 AC 66 ms
4,376 KB
testcase_30 AC 20 ms
4,376 KB
testcase_31 AC 19 ms
4,380 KB
testcase_32 AC 20 ms
4,376 KB
testcase_33 AC 20 ms
4,376 KB
testcase_34 AC 20 ms
4,380 KB
testcase_35 AC 20 ms
4,376 KB
testcase_36 AC 15 ms
4,380 KB
testcase_37 AC 20 ms
4,384 KB
testcase_38 AC 55 ms
4,380 KB
testcase_39 AC 54 ms
4,376 KB
testcase_40 AC 65 ms
4,384 KB
testcase_41 AC 24 ms
4,380 KB
testcase_42 AC 24 ms
4,380 KB
testcase_43 AC 25 ms
4,384 KB
testcase_44 AC 26 ms
4,376 KB
testcase_45 AC 25 ms
4,380 KB
testcase_46 AC 19 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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" });
}
0