結果

問題 No.1267 Stop and Coin Game
ユーザー fura
提出日時 2020-10-23 22:31:12
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 472 bytes
コンパイル時間 2,190 ms
コンパイル使用メモリ 192,144 KB
最終ジャッジ日時 2025-01-15 13:29:27
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 40 TLE * 3
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:19:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   19 |         scanf("%d%lld",&n,&v);
      |         ~~~~~^~~~~~~~~~~~~~~~
main.cpp:20:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   20 |         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 dfs(int S){
	rep(i,n) if(~S>>i&1) {
		if(sum[S]+a[i]<=v && !dfs(S|1<<i)) return true;
	}
	return 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