結果
問題 | No.1267 Stop and Coin Game |
ユーザー |
|
提出日時 | 2021-11-12 05:11:41 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,275 bytes |
コンパイル時間 | 2,285 ms |
コンパイル使用メモリ | 197,036 KB |
最終ジャッジ日時 | 2025-01-25 15:21:52 |
ジャッジサーバーID (参考情報) |
judge8 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 27 WA * 16 |
ソースコード
#include <bits/stdc++.h>using namespace std;long long int A[20];long long int N,V;int dp[1<<20];long long int sum[1<<20];int dfs(int state){if(dp[state]!=-1){return dp[state];}if(sum[state] > V){dp[state] = 0;return dp[state];}set <int> S;for(int i=0;i<N;i++){if((state&(1<<i))==0){S.insert(dfs(state + (1<<i)));}}int g = 0;while(1){if(S.find(g)==S.end()){break;}g++;}dp[state] = g;return dp[state];}int main(void){cin.tie(0);ios::sync_with_stdio(false);cin >> N >> V;for(int i=0;i<N;i++){cin >> A[i];}for(int i=0;i<(1<<N);i++){for(int j=0;j<N;j++){if((i&(1<<j))){sum[i] += A[j];}}}if(sum[(1<<N)-1] <= V){cout << "Draw" << '\n';return 0;}memset(dp,-1,sizeof(dp));dfs(0);int XOR = 0;for(int i=0;i<N;i++){XOR^=dp[(1<<i)];}if(XOR==0){cout << "Second" << '\n';}else{cout << "First" << '\n';}return 0;}