結果
問題 | No.1267 Stop and Coin Game |
ユーザー |
![]() |
提出日時 | 2020-10-24 00:04:47 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 182 ms / 2,000 ms |
コード長 | 1,192 bytes |
コンパイル時間 | 1,645 ms |
コンパイル使用メモリ | 177,880 KB |
実行使用メモリ | 17,708 KB |
最終ジャッジ日時 | 2024-07-21 14:04:03 |
合計ジャッジ時間 | 3,425 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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;namespace std {template <>class hash<std::pair<ll, int>> {public:size_t operator()(const std::pair<ll, int>& x) const{return hash<ll>()(x.first) ^ hash<ll>()(x.second);}};}unordered_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;}if(canwin(V, 0)) cout << "First" << endl;else cout << "Second" << endl;return 0;}