結果
問題 | No.107 モンスター |
ユーザー | htensai |
提出日時 | 2020-01-28 17:52:44 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 187 ms / 5,000 ms |
コード長 | 1,796 bytes |
コンパイル時間 | 2,145 ms |
コンパイル使用メモリ | 73,996 KB |
実行使用メモリ | 127,260 KB |
最終ジャッジ日時 | 2023-10-13 20:48:37 |
合計ジャッジ時間 | 5,473 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 44 ms
49,600 KB |
testcase_01 | AC | 44 ms
49,096 KB |
testcase_02 | AC | 44 ms
49,236 KB |
testcase_03 | AC | 44 ms
49,100 KB |
testcase_04 | AC | 45 ms
48,992 KB |
testcase_05 | AC | 44 ms
49,036 KB |
testcase_06 | AC | 44 ms
49,220 KB |
testcase_07 | AC | 43 ms
49,536 KB |
testcase_08 | AC | 44 ms
49,240 KB |
testcase_09 | AC | 44 ms
49,372 KB |
testcase_10 | AC | 45 ms
49,344 KB |
testcase_11 | AC | 45 ms
49,188 KB |
testcase_12 | AC | 45 ms
49,080 KB |
testcase_13 | AC | 92 ms
57,272 KB |
testcase_14 | AC | 138 ms
84,832 KB |
testcase_15 | AC | 138 ms
84,944 KB |
testcase_16 | AC | 45 ms
49,216 KB |
testcase_17 | AC | 78 ms
54,384 KB |
testcase_18 | AC | 154 ms
91,640 KB |
testcase_19 | AC | 154 ms
92,004 KB |
testcase_20 | AC | 102 ms
65,428 KB |
testcase_21 | AC | 101 ms
65,160 KB |
testcase_22 | AC | 104 ms
61,320 KB |
testcase_23 | AC | 187 ms
127,260 KB |
testcase_24 | AC | 155 ms
84,548 KB |
ソースコード
import java.util.*; import java.io.*; public class Main { static int n; static int[][][] dp; static int[] monsters; public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); n = Integer.parseInt(br.readLine()); monsters = new int[n]; String[] line = br.readLine().split(" ", n); int m = 0; for (int i = 0; i < n; i++) { monsters[i] = Integer.parseInt(line[i]); if (monsters[i] < 0) { m++; } } dp = new int[n + 1][m + 1][(int)(Math.pow(2, n))]; for (int i = 0; i <= n; i++) { for (int j = 0; j <= m; j++) { Arrays.fill(dp[i][j], -1); } } dp[0][0][0] = 100; System.out.println(dfw(n, m, (int)(Math.pow(2, n)) - 1)); } static int dfw(int idx, int count, int key) { if (idx < 0) { return 0; } if (dp[idx][count][key] != -1) { return dp[idx][count][key]; } int max = 0; for (int i = 0; i < n; i++) { int x = (int)(Math.pow(2, i)); if ((x & key) == 0) { continue; } if (monsters[i] < 0) { int tmp = dfw(idx - 1, count - 1, key ^ x); if (tmp != 0) { max = Math.max(max, Math.max(0, tmp + monsters[i])); } } else { int tmp = dfw(idx - 1, count, key ^ x); if (tmp != 0) { max = Math.max(max, Math.min(100 * (count + 1), tmp + monsters[i])); } } } dp[idx][count][key] = max; return max; } }