結果
問題 | No.1267 Stop and Coin Game |
ユーザー |
![]() |
提出日時 | 2020-10-23 23:53:01 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 731 ms / 2,000 ms |
コード長 | 1,018 bytes |
コンパイル時間 | 1,969 ms |
コンパイル使用メモリ | 179,996 KB |
実行使用メモリ | 21,632 KB |
最終ジャッジ日時 | 2024-07-21 13:54:18 |
合計ジャッジ時間 | 4,459 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 43 |
ソースコード
#include <bits/stdc++.h>using namespace std;#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)#define rep(i,n) REP(i,0,n)#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)#define ALLOF(c) (c).begin(), (c).end()typedef long long ll;typedef unsigned long long ull;int N;ll V;vector<ll> v;map<pair<ll,int>,bool> memo;bool canwin(ll remain, int used){if(remain < 0) return true;if(memo.count(make_pair(remain,used)) > 0) return memo[make_pair(remain,used)];bool ret = false;rep(i,N){if((used>>i)&1) continue;if(!canwin(remain-v[i], used | (1<<i))){ret = true;break;}}return memo[make_pair(remain,used)] = ret;}int main(){cin >> N >> V;ll sum = 0;rep(i,N){ll a;cin >> a;v.push_back(a);sum += a;}if(V >= sum){cout << "Draw" << endl;return 0;}sort(ALLOF(v));reverse(ALLOF(v));if(canwin(V, 0)) cout << "First" << endl;else cout << "Second" << endl;return 0;}