結果
問題 | No.1267 Stop and Coin Game |
ユーザー | merom686 |
提出日時 | 2020-10-23 22:33:08 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 17 ms / 2,000 ms |
コード長 | 941 bytes |
コンパイル時間 | 1,079 ms |
コンパイル使用メモリ | 90,388 KB |
最終ジャッジ日時 | 2025-01-15 13:30:43 |
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 43 |
ソースコード
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <cstdio> #include <cstring> #include <cmath> using namespace std; using ll = long long; int n; ll a[20]; char dp[1 << 20]; int dfs(int k, ll v) { if (dp[k] >= 0) return dp[k]; int r = 1; for (int i = 0; i < n; i++) { if (k & 1 << i) continue; ll u = v - a[i]; if (u < 0) continue; if (dfs(k ^ 1 << i, u) == 1) { r = 0; break; } } return dp[k] = r; } int main() { cin >> n; ll v; cin >> v; ll s = 0; for (int i = 0; i < n; i++) { cin >> a[i]; s += a[i]; } if (s <= v) { cout << "Draw" << endl; quick_exit(0); } memset(dp, -1, sizeof(dp)); int r = dfs(0, v); if (r == 0) { cout << "First" << endl; } else if (r == 1) { cout << "Second" << endl; } return 0; }