結果

問題 No.1267 Stop and Coin Game
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-12-23 00:57:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 156 ms / 2,000 ms
コード長 1,175 bytes
コンパイル時間 2,098 ms
コンパイル使用メモリ 206,636 KB
実行使用メモリ 11,644 KB
最終ジャッジ日時 2023-12-23 00:57:53
合計ジャッジ時間 4,915 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 1 ms
6,676 KB
testcase_04 AC 1 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 12 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 105 ms
11,644 KB
testcase_11 AC 36 ms
6,676 KB
testcase_12 AC 7 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 145 ms
11,644 KB
testcase_17 AC 1 ms
6,676 KB
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 2 ms
6,676 KB
testcase_21 AC 2 ms
6,676 KB
testcase_22 AC 2 ms
6,676 KB
testcase_23 AC 2 ms
6,676 KB
testcase_24 AC 41 ms
7,476 KB
testcase_25 AC 98 ms
7,476 KB
testcase_26 AC 2 ms
6,676 KB
testcase_27 AC 4 ms
6,676 KB
testcase_28 AC 2 ms
6,676 KB
testcase_29 AC 2 ms
6,676 KB
testcase_30 AC 77 ms
11,644 KB
testcase_31 AC 3 ms
6,676 KB
testcase_32 AC 11 ms
6,676 KB
testcase_33 AC 38 ms
7,476 KB
testcase_34 AC 78 ms
7,476 KB
testcase_35 AC 75 ms
11,644 KB
testcase_36 AC 2 ms
6,676 KB
testcase_37 AC 23 ms
6,676 KB
testcase_38 AC 156 ms
11,644 KB
testcase_39 AC 13 ms
6,676 KB
testcase_40 AC 2 ms
6,676 KB
testcase_41 AC 13 ms
6,676 KB
testcase_42 AC 2 ms
6,676 KB
testcase_43 AC 23 ms
6,676 KB
testcase_44 AC 2 ms
6,676 KB
testcase_45 AC 2 ms
6,676 KB
testcase_46 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    ll N, M, V, S=0;
    cin >> N >> V;
    M = 1<<N;
    vector<ll> A(N);
    for (int i=0; i<N; i++){
        cin >> A[i];
        S += A[i];
    }
    if (S <= V){
        cout << "Draw" << endl;
        return 0;
    }
    vector<bool> dp(M);
    vector<ll> sm(M);
    auto pop_count=[](int i)->int{
        return __builtin_popcount(i);
    };
    for (int i=0; i<M; i++){
        for (int j=0; j<N; j++){
            if (i & 1<<j) sm[i] += A[j];
        }
        if (sm[i] > V){
            dp[i] = (pop_count(i) % 2 == 1 ? 0 : 1);
        }
    }

    for (int i=M-1; i>=0; i--){
        if (sm[i] > V) continue;
        bool f=0;
        for (int j=0; j<N; j++){
            if (i & 1<<j) continue;
            if (pop_count(i) % 2 == 0 && dp[i|1<<j] == 1) f = 1;
            if (pop_count(i) % 2 == 1 && dp[i|1<<j] == 0) f = 1;
        }
        if (f) dp[i] = (pop_count(i) % 2 == 0 ? 1 : 0);
        else dp[i] = (pop_count(i) % 2 == 0 ? 0 : 1);
    }

    cout << (dp[0] ? "First" : "Second") << endl;

    return 0;
}
0