結果
問題 | No.1267 Stop and Coin Game |
ユーザー |
![]() |
提出日時 | 2020-10-23 22:28:10 |
言語 | Rust (1.83.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,541 bytes |
コンパイル時間 | 15,342 ms |
コンパイル使用メモリ | 379,108 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-21 11:14:33 |
合計ジャッジ時間 | 16,920 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 34 WA * 9 |
ソースコード
#![allow(unused_imports)] use std::cmp::*; use std::collections::*; use std::io::Write; use std::ops::Bound::*; #[allow(unused_macros)] macro_rules! debug { ($($e:expr),*) => { #[cfg(debug_assertions)] $({ let (e, mut err) = (stringify!($e), std::io::stderr()); writeln!(err, "{} = {:?}", e, $e).unwrap() })* }; } fn main() { let v = read_vec::<i64>(); let (n, v) = (v[0] as usize, v[1]); let a = read_vec::<i64>(); if a.iter().sum::<i64>() < v { println!("Draw"); return; } let mut dp = vec![false; 1 << n]; 'outer: for state in (0..1 << n).rev() { let weight = (0..n) .filter(|&j| (state >> j) & 1 == 1) .map(|x| a[x]) .sum::<i64>(); dp[state] = true; if weight > v { continue; } for j in 0..n { if (state >> j) & 1 == 1 { continue; } if dp[state | j] { dp[state] = false; continue 'outer; } } } // debug!(dp); if (0..n).all(|x| dp[1 << x]) { println!("Second"); } else { println!("First"); } } fn read<T: std::str::FromStr>() -> T { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.trim().parse().ok().unwrap() } fn read_vec<T: std::str::FromStr>() -> Vec<T> { read::<String>() .split_whitespace() .map(|e| e.parse().ok().unwrap()) .collect() }