結果
| 問題 |
No.1267 Stop and Coin Game
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2022-04-21 17:41:15 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 179 ms / 2,000 ms |
| コード長 | 1,682 bytes |
| コンパイル時間 | 2,358 ms |
| コンパイル使用メモリ | 76,716 KB |
| 実行使用メモリ | 39,452 KB |
| 最終ジャッジ日時 | 2024-06-22 21:09:00 |
| 合計ジャッジ時間 | 7,189 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 43 |
ソースコード
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();
}
}
tenten