結果

問題 No.1267 Stop and Coin Game
ユーザー KudeKude
提出日時 2020-10-23 23:10:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 850 ms / 2,000 ms
コード長 1,668 bytes
コンパイル時間 2,345 ms
コンパイル使用メモリ 207,612 KB
実行使用メモリ 83,968 KB
最終ジャッジ日時 2023-09-28 17:52:37
合計ジャッジ時間 8,266 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 26 ms
8,988 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 388 ms
59,744 KB
testcase_11 AC 139 ms
21,120 KB
testcase_12 AC 17 ms
6,204 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 729 ms
78,320 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 103 ms
26,616 KB
testcase_25 AC 601 ms
56,592 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 8 ms
4,536 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 187 ms
48,216 KB
testcase_31 AC 4 ms
4,380 KB
testcase_32 AC 25 ms
8,716 KB
testcase_33 AC 96 ms
25,740 KB
testcase_34 AC 388 ms
44,628 KB
testcase_35 AC 189 ms
48,124 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 95 ms
14,792 KB
testcase_38 AC 850 ms
83,968 KB
testcase_39 AC 38 ms
8,664 KB
testcase_40 AC 2 ms
4,376 KB
testcase_41 AC 38 ms
9,380 KB
testcase_42 AC 1 ms
4,380 KB
testcase_43 AC 122 ms
16,196 KB
testcase_44 AC 1 ms
4,380 KB
testcase_45 AC 2 ms
4,376 KB
testcase_46 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = (n)-1; i >= 0; --i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;

std::vector<int> compute_grundy(std::vector<std::vector<int>>& to) {
	int sz = to.size();
	std::vector<int> vsorted(sz);
	std::vector<int> indeg(sz);
	for(int i = 0; i < sz; i++) for(int j: to[i]) indeg[j]++;
	std::vector<int> avail;
	for(int i = 0; i < sz; i++) if (indeg[i] == 0) avail.push_back(i);
	int nxt_idx = 0;
	while(!avail.empty()) {
		int u = avail.back(); avail.pop_back();
		vsorted[nxt_idx++] = u;
		for(int v: to[u]) if (--indeg[v] == 0) avail.push_back(v);
	}
	std::vector<int> grundy(sz), used(sz, -1);
	for(int i = sz - 1; i >= 0; i--) {
		int u = vsorted[i];
		for(int v: to[u]) used[grundy[v]] = u;
		int g = 0;
		while(used[g] == u) g++;
		grundy[u] = g;
	}
	return grundy;
}

int main() {
    int n;
    ll v;
    cin >> n >> v;
    vector<ll> a(n);
    ll tot = 0;
    rep(i, n) {
        cin >> a[i];
        tot += a[i];
    }
    if (tot <= v) {
        cout << "Draw" << endl;
        return 0;
    }
    int smx = 1 << n;
    VVI to(smx);
    rep(s, smx) {
        ll now = 0;
        rep(i, n) if (s >> i & 1) now += a[i];
        rep(i, n) if ((s >> i & 1) == 0 && now + a[i] <= v) {
            to[s].push_back(s | 1 << i);
        }
    }
    auto g = compute_grundy(to);
    if (g[0]) cout << "First" << endl;
    else cout << "Second" << endl;
}
0