結果
問題 |
No.1267 Stop and Coin Game
|
ユーザー |
|
提出日時 | 2021-11-12 05:33:10 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 94 ms / 2,000 ms |
コード長 | 1,069 bytes |
コンパイル時間 | 2,047 ms |
コンパイル使用メモリ | 191,544 KB |
最終ジャッジ日時 | 2025-01-25 15:22:12 |
ジャッジサーバーID (参考情報) |
judge6 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 43 |
ソースコード
#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(sum[state] > V) { return 1; } if(dp[state]!=-1) { return dp[state]; } for(int i=0;i<N;i++) { if((state&(1<<i))) continue; if(!dfs(state | (1<<i))) { dp[state] = 1; return dp[state]; } } dp[state] = 0; 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)); if(dfs(0)) { cout << "First" << '\n'; } else{ cout << "Second" << '\n'; } return 0; }