結果

問題 No.1267 Stop and Coin Game
ユーザー phsplsphspls
提出日時 2022-11-20 16:49:56
言語 Rust
(1.77.0)
結果
TLE  
実行時間 -
コード長 1,133 bytes
コンパイル時間 815 ms
コンパイル使用メモリ 173,548 KB
実行使用メモリ 14,524 KB
最終ジャッジ日時 2023-10-21 14:49:52
合計ジャッジ時間 5,267 ms
ジャッジサーバーID
(参考情報)
judge11 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 86 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 TLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

const INF: usize = 1usize << 60;

fn dfs(cur: usize, n: usize, rest: usize, a: &Vec<usize>, used: &mut Vec<usize>) {
    let mut flg = true;
    for i in 0..n {
        if ((cur >> i) & 1) == 1 { continue; }
        let nval = cur | (1 << i);
        if a[i] > rest {
            used[nval] = 0;
            continue;
        }
        dfs(nval, n, rest - a[i], a, used);
        flg &= used[nval] == 0;
    }
    if flg {
        used[cur] = 1;
    } else {
        used[cur] = 0;
    }
}

fn main() {
    let mut nv = String::new();
    std::io::stdin().read_line(&mut nv).ok();
    let nv: Vec<usize> = nv.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let n = nv[0];
    let v = nv[1];
    let mut a = String::new();
    std::io::stdin().read_line(&mut a).ok();
    let a: Vec<usize> = a.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();

    if v >= a.iter().sum::<usize>() {
        println!("Draw");
        return;
    }
    let mut used = vec![INF; 1<<n];
    dfs(0, n, v, &a, &mut used);
    if used[0] == 0 {
        println!("First");
    } else {
        println!("Second");
    }
}
0