結果
問題 | No.1267 Stop and Coin Game |
ユーザー |
![]() |
提出日時 | 2020-10-23 22:33:54 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,794 bytes |
コンパイル時間 | 2,275 ms |
コンパイル使用メモリ | 194,100 KB |
最終ジャッジ日時 | 2025-01-15 13:31:18 |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 42 WA * 1 |
ソースコード
// #pragma GCC target("avx2") // #pragma GCC optimize("O3") // #pragma GCC optimize("unroll-loops") #include<bits/stdc++.h> using namespace std; typedef long long ll; #define endl '\n' #define all(x) (x).begin(),(x).end() template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;} template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;} int dx[4]={0,1,0,-1}, dy[4]={1,0,-1,0}; long double eps = 1e-9; long double pi = acos(-1); int dp[(1<<20)]; int next_combination(int sub) { int x = sub & -sub, y = sub + x; return (((sub & ~y) / x) >> 1) | y; } signed main(){ ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20); ll n,m; cin>>n>>m; ll sum = 0; ll a[n]; for(int i=0;i<n;i++){ cin>>a[i]; sum += a[i]; } if(sum < m){ cout << "Draw\n"; return 0; } for(int bit=0;bit<(1<<n);bit++){ ll now = 0; int cnt = 0; for(int i=0;i<n;i++){ if(bit & (1<<i)){ cnt++; now += a[i]; cnt %= 2; } } if(now > m)dp[bit] = cnt^1; else dp[bit] = -1; } for(int k=n;k>=0;k--){ for (int bit = (1<<k)-1 ;bit < (1LL<<n); bit = next_combination(bit)) { if(dp[bit] != -1)continue; bool win = 0; int f = (k%2==0); for(int i=0;i<n;i++){ if(bit & (1<<i))continue; int nb = bit | (1<<i); if(dp[nb] == f)win = 1; } if(win)dp[bit] = f; else dp[bit] = f^1; if(bit == 0)break; } } if(dp[0])cout << "First\n"; else cout << "Second" << endl; }