結果

問題 No.1267 Stop and Coin Game
ユーザー yamakeyamake
提出日時 2020-10-23 23:33:17
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 80 ms / 2,000 ms
コード長 1,352 bytes
コンパイル時間 803 ms
コンパイル使用メモリ 82,172 KB
実行使用メモリ 19,536 KB
最終ジャッジ日時 2023-09-28 18:48:18
合計ジャッジ時間 3,262 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
19,424 KB
testcase_01 AC 6 ms
19,432 KB
testcase_02 AC 7 ms
19,220 KB
testcase_03 AC 7 ms
19,220 KB
testcase_04 AC 7 ms
19,352 KB
testcase_05 AC 7 ms
19,360 KB
testcase_06 AC 7 ms
19,360 KB
testcase_07 AC 7 ms
19,288 KB
testcase_08 AC 7 ms
19,440 KB
testcase_09 AC 7 ms
19,252 KB
testcase_10 AC 54 ms
19,220 KB
testcase_11 AC 16 ms
19,428 KB
testcase_12 AC 10 ms
19,352 KB
testcase_13 AC 7 ms
19,512 KB
testcase_14 AC 7 ms
19,432 KB
testcase_15 AC 7 ms
19,244 KB
testcase_16 AC 47 ms
19,352 KB
testcase_17 AC 7 ms
19,232 KB
testcase_18 AC 7 ms
19,336 KB
testcase_19 AC 7 ms
19,524 KB
testcase_20 AC 7 ms
19,432 KB
testcase_21 AC 7 ms
19,348 KB
testcase_22 AC 7 ms
19,236 KB
testcase_23 AC 7 ms
19,464 KB
testcase_24 AC 9 ms
19,272 KB
testcase_25 AC 80 ms
19,344 KB
testcase_26 AC 7 ms
19,424 KB
testcase_27 AC 7 ms
19,348 KB
testcase_28 AC 7 ms
19,236 KB
testcase_29 AC 7 ms
19,288 KB
testcase_30 AC 8 ms
19,272 KB
testcase_31 AC 7 ms
19,336 KB
testcase_32 AC 7 ms
19,276 KB
testcase_33 AC 7 ms
19,472 KB
testcase_34 AC 60 ms
19,528 KB
testcase_35 AC 7 ms
19,456 KB
testcase_36 AC 7 ms
19,428 KB
testcase_37 AC 24 ms
19,268 KB
testcase_38 AC 55 ms
19,416 KB
testcase_39 AC 10 ms
19,332 KB
testcase_40 AC 7 ms
19,224 KB
testcase_41 AC 8 ms
19,340 KB
testcase_42 AC 7 ms
19,236 KB
testcase_43 AC 9 ms
19,368 KB
testcase_44 AC 7 ms
19,292 KB
testcase_45 AC 7 ms
19,352 KB
testcase_46 AC 7 ms
19,536 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cstdio>
#include<cmath>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define debug(output) cout<<#output<<"= "<<output<<endl
using lint=long long;
int MOD=1000000007;
vector<int> memo((1ll<<22),2);
lint n,v;

bool rec(lint bit,vector<lint>& a){
    lint sm=0;
    if(memo[bit]!=2)return memo[bit]==1;
    rep(i,n){
        if(bit&(1<<i))sm+=a[i];
    }
    if(sm>v){
        memo[bit]=1;
        return true;
    }
    rep(i,n){
        if(!(bit&(1<<i))){
            if(sm+a[i]>v){
                memo[bit]=0;
                return false;
            }
            else break;
        }
    }
    bool flag=false;
    rep(i,n){
        if(!(bit&(1<<i))){
            flag=flag||!rec(bit+(1<<i),a);
        }
    }
    if(flag)memo[bit]=1;
    else memo[bit]=0;
    
    return flag;
}
signed main(){
    cin>>n;
    cin>>v;
    vector<lint> a(n);
    rep(i,n)cin>>a[i];
    sort(a.begin(),a.end());
    lint status=0;
    
    lint sm=0;
    rep(i,n)sm+=a[i];
    if(sm<=v){
        cout<<"Draw"<<"\n";
        return 0;
    }
    bool flag=rec(status,a);
	if(flag){
        cout<<"First"<<endl;
    }
    else{
        cout<<"Second"<<endl;
    }

    return 0;
}
0