結果

問題 No.1267 Stop and Coin Game
ユーザー milanis48663220
提出日時 2020-10-23 22:53:35
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 114 ms / 2,000 ms
コード長 1,212 bytes
コンパイル時間 993 ms
コンパイル使用メモリ 83,012 KB
実行使用メモリ 12,672 KB
最終ジャッジ日時 2024-07-21 12:03:37
合計ジャッジ時間 3,005 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int n;
ll v;
ll a[20];
void input(){
cin >> n >> v;
for(int i = 0; i < n; i++) cin >> a[i];
}
bool win[1<<20];
ll sum[1<<20];
void process(int i){
int cnt = 0;
for(int j = 0; j < n; j++){
if(i&(1<<j)) {
cnt++;
sum[i] += a[j];
}
}
if(sum[i] > v){
return;
}
bool is_first = (cnt%2) == 0;
for(int j = 0; j < n; j++){
if(i&(1<<j)) continue;
int k = i+(1<<j);
if(sum[k] <= v && win[k] == false){
win[i] = true;
return;
}
}
win[i] = false;
}
void solve(){
ll sum_all = 0;
for(int i = 0; i < n; i++) sum_all += a[i];
if(sum_all <= v){
cout << "Draw" << endl;
return;
}
for(int i = (1<<n)-1; i >= 0; i--){
process(i);
}
if(win[0]){
cout << "First" << endl;
}else{
cout << "Second" << endl;
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout << setprecision(10) << fixed;
input();
solve();
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0