結果

問題 No.1267 Stop and Coin Game
ユーザー polylogKpolylogK
提出日時 2020-10-23 23:00:51
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 136 ms / 2,000 ms
コード長 1,106 bytes
コンパイル時間 2,129 ms
コンパイル使用メモリ 201,400 KB
実行使用メモリ 15,712 KB
最終ジャッジ日時 2023-09-28 17:31:22
合計ジャッジ時間 4,716 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 11 ms
4,600 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 96 ms
15,552 KB
testcase_11 AC 32 ms
6,180 KB
testcase_12 AC 6 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 127 ms
15,536 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 39 ms
9,288 KB
testcase_25 AC 86 ms
9,360 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 4 ms
4,376 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 73 ms
15,524 KB
testcase_31 AC 3 ms
4,376 KB
testcase_32 AC 10 ms
4,532 KB
testcase_33 AC 37 ms
9,288 KB
testcase_34 AC 69 ms
9,292 KB
testcase_35 AC 74 ms
15,548 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 20 ms
4,652 KB
testcase_38 AC 136 ms
15,712 KB
testcase_39 AC 10 ms
4,380 KB
testcase_40 AC 1 ms
4,376 KB
testcase_41 AC 11 ms
4,376 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 19 ms
4,708 KB
testcase_44 AC 2 ms
4,376 KB
testcase_45 AC 2 ms
4,376 KB
testcase_46 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n; i64 V; scanf("%d%lld", &n, &V);
	std::vector<i64> a(n);
	for(auto& v: a) scanf("%lld", &v);

	if(V - std::accumulate(begin(a), end(a), 0LL) >= 0) {
		printf("Draw\n");
		return 0;
	}

	std::vector<i64> sum(1 << n);
	for(int i = 0; i < (1 << n); i++) {
		for(int j = 0; j < n; j++) {
			if(!(i >> j & 1)) continue;
			sum[i] += a[j];
		}
	}

	std::vector<int> dp(1 << n, 2);
	for(int i = (1 << n) - 1; i >= 0; i--) {
		if(V - sum[i] < 0) {
			dp[i] = 1;
			continue;
		}

		for(int k = 0; k < n; k++) {
			if(i >> k & 1) continue;
			int to = i | (1 << k);
			if(dp[to] == 0) dp[i] = 1;
		}
		if(dp[i] == 2) dp[i] = 0;
	}

	if(dp[0]) printf("First\n");
	else printf("Second\n");
	return 0;
}
0