結果
問題 | No.1267 Stop and Coin Game |
ユーザー |
![]() |
提出日時 | 2020-10-23 23:00:35 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 423 ms / 2,000 ms |
コード長 | 840 bytes |
コンパイル時間 | 276 ms |
コンパイル使用メモリ | 32,000 KB |
実行使用メモリ | 15,360 KB |
最終ジャッジ日時 | 2024-07-21 12:09:49 |
合計ジャッジ時間 | 3,445 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 43 |
ソースコード
#include <stdio.h> int a; long long int b; long long int x[110]; long long int sum[2000010]; int check[2000010]; int func(int bit) { if(bit+1==(1<<a)) { return 2; } if(check[bit]) return check[bit]; //1win 2draw 3lose int count[5]={}; for(int i=1;i<=a;i++) { if((bit&(1<<(i-1)))==0) { int newBit = bit+(1<<(i-1)); if(sum[newBit]<=b) count[func(newBit)]++; } } if(count[3]>0) return check[bit] = 1; else if(count[2]>0) return check[bit] = 2; return check[bit] = 3; } long long int C = 0; void init(int k, int S) { if(k>a) { sum[S] = C; return; } init(k+1,S); C += x[k]; init(k+1,S+(1<<(k-1))); C -= x[k]; } int main() { scanf("%d%lld",&a,&b); for(int i=1;i<=a;i++) scanf("%lld",&x[i]); init(1,0); int k = func(0); if(k==1) printf("First"); else if(k==2) printf("Draw"); else printf("Second"); }