結果

問題 No.1267 Stop and Coin Game
ユーザー fura
提出日時 2020-10-23 22:32:12
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 127 ms / 2,000 ms
コード長 573 bytes
コンパイル時間 2,168 ms
コンパイル使用メモリ 192,672 KB
最終ジャッジ日時 2025-01-15 13:29:52
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 43
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:25:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   25 |         scanf("%d%lld",&n,&v);
      |         ~~~~~^~~~~~~~~~~~~~~~
main.cpp:26:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   26 |         rep(i,n) scanf("%lld",&a[i]);
      |                  ~~~~~^~~~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

int n;
lint v,a[20],sum[1<<20];

bool vis[1<<20],memo[1<<20];

bool dfs(int S){
	if(vis[S]) return memo[S];
	vis[S]=true;

	bool& res=memo[S];
	rep(i,n) if(~S>>i&1) {
		if(sum[S]+a[i]<=v && !dfs(S|1<<i)) return res=true;
	}
	return res=false;
}

int main(){
	scanf("%d%lld",&n,&v);
	rep(i,n) scanf("%lld",&a[i]);

	rep(S,1<<n) rep(i,n) if(S>>i&1) sum[S]+=a[i];
	if(sum[(1<<n)-1]<=v){
		puts("Draw");
		return 0;
	}

	puts(dfs(0)?"First":"Second");

	return 0;
}
0