結果
| 問題 |
No.1267 Stop and Coin Game
|
| コンテスト | |
| ユーザー |
srjywrdnprkt
|
| 提出日時 | 2023-12-23 00:57:48 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 171 ms / 2,000 ms |
| コード長 | 1,175 bytes |
| コンパイル時間 | 2,243 ms |
| コンパイル使用メモリ | 197,860 KB |
| 最終ジャッジ日時 | 2025-02-18 13:21:34 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 43 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
ll N, M, V, S=0;
cin >> N >> V;
M = 1<<N;
vector<ll> A(N);
for (int i=0; i<N; i++){
cin >> A[i];
S += A[i];
}
if (S <= V){
cout << "Draw" << endl;
return 0;
}
vector<bool> dp(M);
vector<ll> sm(M);
auto pop_count=[](int i)->int{
return __builtin_popcount(i);
};
for (int i=0; i<M; i++){
for (int j=0; j<N; j++){
if (i & 1<<j) sm[i] += A[j];
}
if (sm[i] > V){
dp[i] = (pop_count(i) % 2 == 1 ? 0 : 1);
}
}
for (int i=M-1; i>=0; i--){
if (sm[i] > V) continue;
bool f=0;
for (int j=0; j<N; j++){
if (i & 1<<j) continue;
if (pop_count(i) % 2 == 0 && dp[i|1<<j] == 1) f = 1;
if (pop_count(i) % 2 == 1 && dp[i|1<<j] == 0) f = 1;
}
if (f) dp[i] = (pop_count(i) % 2 == 0 ? 1 : 0);
else dp[i] = (pop_count(i) % 2 == 0 ? 0 : 1);
}
cout << (dp[0] ? "First" : "Second") << endl;
return 0;
}
srjywrdnprkt