結果

問題 No.1267 Stop and Coin Game
ユーザー milanis48663220milanis48663220
提出日時 2020-10-23 22:53:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 110 ms / 2,000 ms
コード長 1,212 bytes
コンパイル時間 709 ms
コンパイル使用メモリ 82,556 KB
実行使用メモリ 12,864 KB
最終ジャッジ日時 2023-09-28 17:23:59
合計ジャッジ時間 3,455 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 12 ms
4,796 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 91 ms
12,864 KB
testcase_11 AC 27 ms
5,792 KB
testcase_12 AC 6 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 107 ms
12,656 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 40 ms
7,964 KB
testcase_25 AC 60 ms
8,000 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 4 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 78 ms
11,732 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 11 ms
4,452 KB
testcase_33 AC 39 ms
7,628 KB
testcase_34 AC 56 ms
7,992 KB
testcase_35 AC 77 ms
11,580 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 16 ms
4,544 KB
testcase_38 AC 110 ms
12,656 KB
testcase_39 AC 8 ms
4,376 KB
testcase_40 AC 2 ms
4,376 KB
testcase_41 AC 8 ms
4,380 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 16 ms
4,832 KB
testcase_44 AC 2 ms
4,376 KB
testcase_45 AC 1 ms
4,380 KB
testcase_46 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int n;
ll v;
ll a[20];

void input(){
    cin >> n >> v;
    for(int i = 0; i < n; i++) cin >> a[i];
}

bool win[1<<20];
ll sum[1<<20];

void process(int i){
    int cnt = 0;
    for(int j = 0; j < n; j++){
        if(i&(1<<j)) {
            cnt++;
            sum[i] += a[j];
        }
    }
    if(sum[i] > v){
        return;
    }
    bool is_first = (cnt%2) == 0;
    for(int j = 0; j < n; j++){
        if(i&(1<<j)) continue;
        int k = i+(1<<j);
        if(sum[k] <= v && win[k] == false){
            win[i] = true;
            return;
        }
    }
    win[i] = false;
}

void solve(){
    ll sum_all = 0;
    for(int i = 0; i < n; i++) sum_all += a[i];
    if(sum_all <= v){
        cout << "Draw" << endl;
        return;
    }
    for(int i = (1<<n)-1; i >= 0; i--){
        process(i);
    }
    if(win[0]){
        cout << "First" << endl;
    }else{
        cout << "Second" << endl;
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    input();
    solve();
}
0