結果

問題 No.1267 Stop and Coin Game
ユーザー tentententen
提出日時 2022-04-21 17:41:15
言語 Java21
(openjdk 21)
結果
AC  
実行時間 186 ms / 2,000 ms
コード長 1,682 bytes
コンパイル時間 3,832 ms
コンパイル使用メモリ 74,036 KB
実行使用メモリ 52,292 KB
最終ジャッジ日時 2023-09-04 23:55:28
合計ジャッジ時間 9,016 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
47,340 KB
testcase_01 AC 42 ms
49,756 KB
testcase_02 AC 41 ms
49,532 KB
testcase_03 AC 41 ms
49,832 KB
testcase_04 AC 42 ms
49,112 KB
testcase_05 AC 47 ms
49,844 KB
testcase_06 AC 42 ms
49,252 KB
testcase_07 AC 41 ms
49,304 KB
testcase_08 AC 73 ms
52,276 KB
testcase_09 AC 42 ms
49,532 KB
testcase_10 AC 169 ms
51,384 KB
testcase_11 AC 81 ms
51,912 KB
testcase_12 AC 63 ms
51,596 KB
testcase_13 AC 42 ms
49,184 KB
testcase_14 AC 42 ms
49,248 KB
testcase_15 AC 43 ms
49,312 KB
testcase_16 AC 145 ms
52,244 KB
testcase_17 AC 43 ms
49,344 KB
testcase_18 AC 45 ms
49,228 KB
testcase_19 AC 43 ms
49,232 KB
testcase_20 AC 44 ms
49,112 KB
testcase_21 AC 43 ms
47,220 KB
testcase_22 AC 46 ms
49,680 KB
testcase_23 AC 43 ms
49,104 KB
testcase_24 AC 116 ms
51,660 KB
testcase_25 AC 104 ms
51,464 KB
testcase_26 AC 45 ms
49,352 KB
testcase_27 AC 55 ms
50,628 KB
testcase_28 AC 52 ms
50,016 KB
testcase_29 AC 44 ms
49,636 KB
testcase_30 AC 179 ms
51,612 KB
testcase_31 AC 48 ms
49,328 KB
testcase_32 AC 71 ms
51,944 KB
testcase_33 AC 121 ms
51,816 KB
testcase_34 AC 100 ms
50,900 KB
testcase_35 AC 186 ms
52,292 KB
testcase_36 AC 48 ms
49,200 KB
testcase_37 AC 69 ms
51,764 KB
testcase_38 AC 145 ms
51,780 KB
testcase_39 AC 63 ms
52,032 KB
testcase_40 AC 52 ms
50,240 KB
testcase_41 AC 66 ms
51,380 KB
testcase_42 AC 45 ms
49,684 KB
testcase_43 AC 71 ms
51,540 KB
testcase_44 AC 146 ms
51,784 KB
testcase_45 AC 42 ms
49,784 KB
testcase_46 AC 42 ms
49,200 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        long v = sc.nextLong();
        long[] values = new long[n];
        for (int i = 0; i < n; i++) {
            values[i] = sc.nextLong();
        }
        boolean[] dp = new boolean[1 << n];
        for (int i = (1 << n) - 1; i >= 0; i--) {
            long total = 0;
            for (int j = 0; j < n; j++) {
                if ((i & (1 << j)) == 0) {
                    dp[i] |= !dp[i ^ (1 << j)];
                } else {
                    total += values[j];
                }
            }
            dp[i] |= (total > v);
        }
        if (dp[(1 << n) - 1]) {
            if (dp[0]) {
                System.out.println("First");
            } else {
                System.out.println("Second");
            }
        } else {
            System.out.println("Draw");
        }
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0