結果

問題 No.1267 Stop and Coin Game
ユーザー chocopuuchocopuu
提出日時 2020-11-27 20:47:43
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 206 ms / 2,000 ms
コード長 1,524 bytes
コンパイル時間 2,046 ms
コンパイル使用メモリ 202,200 KB
実行使用メモリ 19,856 KB
最終ジャッジ日時 2023-10-01 04:22:24
合計ジャッジ時間 4,992 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
13,584 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 5 ms
13,628 KB
testcase_03 AC 5 ms
13,540 KB
testcase_04 AC 5 ms
13,540 KB
testcase_05 AC 5 ms
13,756 KB
testcase_06 AC 5 ms
13,716 KB
testcase_07 AC 5 ms
13,660 KB
testcase_08 AC 13 ms
13,616 KB
testcase_09 AC 5 ms
13,608 KB
testcase_10 AC 127 ms
19,856 KB
testcase_11 AC 38 ms
15,628 KB
testcase_12 AC 9 ms
13,660 KB
testcase_13 AC 5 ms
13,600 KB
testcase_14 AC 5 ms
13,596 KB
testcase_15 AC 5 ms
13,664 KB
testcase_16 AC 194 ms
19,788 KB
testcase_17 AC 5 ms
13,584 KB
testcase_18 AC 6 ms
13,564 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 5 ms
13,716 KB
testcase_21 AC 5 ms
13,604 KB
testcase_22 AC 5 ms
13,656 KB
testcase_23 AC 5 ms
13,672 KB
testcase_24 AC 41 ms
17,744 KB
testcase_25 AC 114 ms
17,688 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 7 ms
13,648 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 5 ms
13,616 KB
testcase_30 AC 73 ms
19,752 KB
testcase_31 AC 6 ms
13,544 KB
testcase_32 AC 13 ms
13,560 KB
testcase_33 AC 40 ms
17,696 KB
testcase_34 AC 100 ms
17,852 KB
testcase_35 AC 73 ms
19,828 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 25 ms
13,592 KB
testcase_38 AC 206 ms
19,728 KB
testcase_39 AC 14 ms
13,600 KB
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 14 ms
13,596 KB
testcase_42 AC 1 ms
4,376 KB
testcase_43 AC 23 ms
13,652 KB
testcase_44 AC 2 ms
4,376 KB
testcase_45 AC 1 ms
4,376 KB
testcase_46 AC 5 ms
13,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
//#include "atcoder/all"
//using namespace atcoder;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>istream&operator >>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
template<class T>inline bool CHMIN(T&a,T b){if(a > b){a = b;return true;}return false;}
template<class T>inline bool CHMAX(T&a,T b){if(a < b){a = b;return true;}return false;}
constexpr int INF = 1e18;

int dp[1ll << 20];
int win[1ll << 20];
int N, V;
vector<int> a;

int dfs(int bit, int turn) {
	if(win[bit] != -1) return win[bit];
	int v = dp[bit];
	if(v > V) {
		return turn ^ 1;
	}
	int ret = 0;
	REP(i, N) {
		if(bit & (1ll << i)) continue;
		ret |= dfs(bit ^ (1ll << i), turn ^ 1) ^ turn;
	}
	return win[bit] = ret ^ turn;
}

signed main(){
	cin >> N >> V;
	a.resize(N);
	cin >> a;
	if(accumulate(ALL(a), 0ll) <= V) {
		out("Draw");
		return 0;
	}
	REP(i, 1ll << N) {
		int sum = 0;
		REP(j, N) {
			if(i & (1ll << j)) sum += a[j];
		}
		dp[i] = sum;
	}
	memset(win, -1, sizeof(win));
	dfs(0, 0);
	if(win[0] == 1) {
		out("First");
	} else {
		out("Second");
	}
}
0