結果

問題 No.1267 Stop and Coin Game
ユーザー ks2mks2m
提出日時 2020-10-23 23:35:47
言語 Java
(openjdk 23)
結果
AC  
実行時間 336 ms / 2,000 ms
コード長 1,087 bytes
コンパイル時間 2,214 ms
コンパイル使用メモリ 76,816 KB
実行使用メモリ 59,888 KB
最終ジャッジ日時 2024-07-21 13:32:33
合計ジャッジ時間 11,550 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long v = sc.nextLong();
		long[] a = new long[n];
		long sum = 0;
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextLong();
			sum += a[i];
		}
		sc.close();

		if (sum <= v) {
			System.out.println("Draw");
			return;
		}

		int n2 = 1 << n;
		long[] tot = new long[n2];
		for (int i = 0; i < n2; i++) {
			for (int j = 0; j < n; j++) {
				if ((i >> j & 1) == 1) {
					tot[i] += a[j];
				}
			}
		}

		int[] dp = new int[n2];
		label:
		for (int i = n2 - 1; i >= 0; i--) {
			if (tot[i] > v) {
				dp[i] = 24;
				continue;
			}
			boolean[] ap = new boolean[25];
			for (int j = 0; j < n; j++) {
				if ((i >> j & 1) == 0) {
					ap[dp[i + (1 << j)]] = true;
				}
			}
			for (int j = 0; j < ap.length; j++) {
				if (!ap[j]) {
					dp[i] = j;
					continue label;
				}
			}
			throw new Exception();
		}
		if (dp[0] == 0) {
			System.out.println("Second");
		} else {
			System.out.println("First");
		}
	}
}
0