結果
問題 | No.1267 Stop and Coin Game |
ユーザー | Strorkis |
提出日時 | 2020-10-24 13:08:26 |
言語 | Rust (1.77.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,655 bytes |
コンパイル時間 | 14,140 ms |
コンパイル使用メモリ | 378,556 KB |
実行使用メモリ | 8,872 KB |
最終ジャッジ日時 | 2024-07-21 15:12:27 |
合計ジャッジ時間 | 16,108 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | WA | - |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 1 ms
5,376 KB |
testcase_04 | AC | 1 ms
5,376 KB |
testcase_05 | AC | 1 ms
5,376 KB |
testcase_06 | AC | 1 ms
5,376 KB |
testcase_07 | AC | 1 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 1 ms
5,376 KB |
testcase_10 | AC | 61 ms
8,852 KB |
testcase_11 | AC | 12 ms
5,376 KB |
testcase_12 | AC | 5 ms
5,376 KB |
testcase_13 | AC | 1 ms
5,376 KB |
testcase_14 | AC | 1 ms
5,376 KB |
testcase_15 | AC | 1 ms
5,376 KB |
testcase_16 | AC | 68 ms
8,852 KB |
testcase_17 | AC | 1 ms
5,376 KB |
testcase_18 | AC | 1 ms
5,376 KB |
testcase_19 | WA | - |
testcase_20 | AC | 1 ms
5,376 KB |
testcase_21 | AC | 1 ms
5,376 KB |
testcase_22 | AC | 1 ms
5,376 KB |
testcase_23 | AC | 1 ms
5,376 KB |
testcase_24 | AC | 3 ms
5,376 KB |
testcase_25 | AC | 77 ms
8,856 KB |
testcase_26 | WA | - |
testcase_27 | AC | 1 ms
5,376 KB |
testcase_28 | WA | - |
testcase_29 | AC | 1 ms
5,376 KB |
testcase_30 | AC | 1 ms
5,376 KB |
testcase_31 | AC | 2 ms
5,376 KB |
testcase_32 | AC | 1 ms
5,376 KB |
testcase_33 | AC | 1 ms
5,376 KB |
testcase_34 | AC | 69 ms
8,872 KB |
testcase_35 | AC | 1 ms
5,376 KB |
testcase_36 | WA | - |
testcase_37 | AC | 17 ms
5,376 KB |
testcase_38 | AC | 18 ms
5,376 KB |
testcase_39 | AC | 6 ms
5,376 KB |
testcase_40 | WA | - |
testcase_41 | AC | 4 ms
5,376 KB |
testcase_42 | WA | - |
testcase_43 | AC | 3 ms
5,376 KB |
testcase_44 | WA | - |
testcase_45 | WA | - |
testcase_46 | AC | 1 ms
5,376 KB |
ソースコード
use std::io::{self, BufRead, Write}; use std::str::FromStr; use std::fmt; struct Io1<T>(T); impl<T: FromStr> FromStr for Io1<T> { type Err = String; fn from_str(s: &str) -> Result<Self, Self::Err> { Ok(s.trim_end().parse().ok().unwrap()) } } struct Io2<T1, T2>(T1, T2); impl<T1: FromStr, T2: FromStr> FromStr for Io2<T1, T2> { type Err = String; fn from_str(s: &str) -> Result<Self, Self::Err> { let mut iter = s.split_whitespace(); Ok(Io2( iter.next().unwrap().parse().ok().unwrap(), iter.next().unwrap().parse().ok().unwrap(), )) } } struct Io3<T1, T2, T3>(T1, T2, T3); impl<T1, T2, T3> FromStr for Io3<T1, T2, T3> where T1: FromStr, T2: FromStr, T3: FromStr { type Err = String; fn from_str(s: &str) -> Result<Self, Self::Err> { let mut iter = s.split_whitespace(); Ok(Io3( iter.next().unwrap().parse().ok().unwrap(), iter.next().unwrap().parse().ok().unwrap(), iter.next().unwrap().parse().ok().unwrap(), )) } } struct Ios(Vec<char>); impl std::str::FromStr for Ios { type Err = String; fn from_str(s: &str) -> Result<Self, Self::Err> { Ok(Ios(s.chars().collect())) } } impl fmt::Display for Ios { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.0.iter().collect::<String>()) } } struct Iov<T>(Vec<T>); impl<T: FromStr> FromStr for Iov<T> { type Err = String; fn from_str(s: &str) -> Result<Self, Self::Err> { let iter = s.split_whitespace(); Ok(Iov(iter.map(|x| x.parse().ok().unwrap()).collect())) } } impl<T: fmt::Display> fmt::Display for Iov<T> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.0.iter().map(|x| x.to_string()) .collect::<Vec<_>>().join(" ") ) } } use std::collections::HashMap; struct Solver<'a> { reader: io::BufReader<io::StdinLock<'a>>, writer: io::BufWriter<io::StdoutLock<'a>>, } impl Solver<'_> { fn read<T: FromStr>(&mut self) -> T { let mut input = String::new(); self.reader.read_line(&mut input).unwrap(); input.trim_end().parse().ok().unwrap() } fn writeln<T: fmt::Display>(&mut self, ans: T) { writeln!(self.writer, "{}", ans).unwrap(); } fn rec( n: usize, a: &Vec<i64>, map: &mut HashMap<i32, bool>, v: i64, mut state: i32, flag: bool ) -> bool { if v < 0 { return flag; } if let Some(value) = map.get(&state) { return *value; } for i in 0..n { if state & 1 << i != 0 { continue; } state |= 1 << i; let value = Self::rec(n, a, map, v - a[i], state, !flag); map.insert(state, value); if value == flag { return flag; } state ^= 1 << i; } !flag } fn solve(&mut self) { let Io2(n, v): Io2<usize, i64> = self.read(); let Iov(a): Iov<i64> = self.read(); if a.iter().sum::<i64>() <= v { self.writeln("Draw"); } let mut map = HashMap::new(); if Self::rec(n, &a, &mut map, v, 0, true) { self.writeln("First"); } else { self.writeln("Second"); } } fn run() { let (stdin, stdout) = (io::stdin(), io::stdout()); let reader = io::BufReader::new(stdin.lock()); let writer = io::BufWriter::new(stdout.lock()); let mut solver = Solver { reader, writer }; solver.solve(); } } fn main() { Solver::run(); }