結果

問題 No.1267 Stop and Coin Game
ユーザー kotatsugame
提出日時 2020-10-24 01:43:00
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 508 bytes
コンパイル時間 634 ms
コンパイル使用メモリ 65,052 KB
実行使用メモリ 7,552 KB
最終ジャッジ日時 2024-07-21 14:46:03
合計ジャッジ時間 2,116 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 43
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:26:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   26 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
using namespace std;
int N;
long V,A[20];
int dp[1<<20];
bool dfs(int st,long now)
{
	if(dp[st])return dp[st]>0;
	if(now<0)
	{
		dp[st]=1;
		return true;
	}
	bool f=false;
	for(int i=0;i<N;i++)if(!(st>>i&1))
	{
		if(!dfs(st|1<<i,now-A[i]))
		{
			f=true;
			break;
		}
	}
	dp[st]=f?1:-1;
	return f;
}
main()
{
	cin>>N>>V;
	long sum=0;
	for(int i=0;i<N;i++)
	{
		cin>>A[i];
		sum+=A[i];
	}
	if(sum<=V)cout<<"Draw"<<endl;
	else if(dfs(0,V))cout<<"First"<<endl;
	else cout<<"Second"<<endl;
}
0