結果

問題 No.1267 Stop and Coin Game
ユーザー totori_nyaatotori_nyaa
提出日時 2020-10-23 22:35:14
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 122 ms / 2,000 ms
コード長 1,795 bytes
コンパイル時間 1,996 ms
コンパイル使用メモリ 199,880 KB
実行使用メモリ 7,672 KB
最終ジャッジ日時 2023-09-28 16:42:32
合計ジャッジ時間 4,600 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 13 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 98 ms
7,484 KB
testcase_11 AC 29 ms
4,592 KB
testcase_12 AC 6 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 117 ms
7,672 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,384 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 44 ms
7,468 KB
testcase_25 AC 72 ms
7,648 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 4 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 83 ms
7,484 KB
testcase_31 AC 3 ms
4,380 KB
testcase_32 AC 12 ms
4,376 KB
testcase_33 AC 42 ms
7,668 KB
testcase_34 AC 62 ms
7,472 KB
testcase_35 AC 83 ms
7,488 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 18 ms
4,380 KB
testcase_38 AC 122 ms
7,484 KB
testcase_39 AC 10 ms
4,376 KB
testcase_40 AC 1 ms
4,380 KB
testcase_41 AC 10 ms
4,376 KB
testcase_42 AC 1 ms
4,380 KB
testcase_43 AC 19 ms
4,376 KB
testcase_44 AC 2 ms
4,376 KB
testcase_45 AC 2 ms
4,384 KB
testcase_46 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
#define endl '\n'
#define all(x) (x).begin(),(x).end()
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,0,-1}, dy[4]={1,0,-1,0};
long double eps = 1e-9;
long double pi = acos(-1);


int dp[(1<<20)];

int next_combination(int sub) {
    int x = sub & -sub, y = sub + x;
    return (((sub & ~y) / x) >> 1) | y;
}


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    ll n,m;
    cin>>n>>m;
    ll sum = 0;
    ll a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum += a[i];
    }
    if(sum <= m){
        cout << "Draw\n";
        return 0;
    }
    for(int bit=0;bit<(1<<n);bit++){
        ll now = 0;
        int cnt = 0;
        for(int i=0;i<n;i++){
            if(bit & (1<<i)){
                cnt++;
                now += a[i];
                cnt %= 2;
            }
        }
        if(now > m)dp[bit] = cnt^1;
        else dp[bit] = -1;
    }

    for(int k=n;k>=0;k--){
        for (int bit = (1<<k)-1 ;bit < (1LL<<n); bit = next_combination(bit)) {
            if(dp[bit] != -1)continue;
            bool win = 0;
            int f = (k%2==0);
            for(int i=0;i<n;i++){
                if(bit & (1<<i))continue;
                int nb = bit | (1<<i);
                if(dp[nb] == f)win = 1;
            }
            if(win)dp[bit] = f;
            else dp[bit] = f^1;
            if(bit == 0)break;
        }   
    }

    if(dp[0])cout << "First\n";
    else cout << "Second" << endl;


}
0