結果
問題 | No.107 モンスター |
ユーザー | takeya_okino |
提出日時 | 2019-07-26 22:33:04 |
言語 | Java19 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,182 bytes |
コンパイル時間 | 3,418 ms |
コンパイル使用メモリ | 79,132 KB |
実行使用メモリ | 57,520 KB |
最終ジャッジ日時 | 2023-09-15 02:27:19 |
合計ジャッジ時間 | 6,436 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | AC | 121 ms
55,760 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | AC | 124 ms
55,928 KB |
testcase_06 | AC | 125 ms
56,164 KB |
testcase_07 | AC | 122 ms
55,472 KB |
testcase_08 | AC | 125 ms
56,204 KB |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | AC | 149 ms
55,768 KB |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
ソースコード
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] d = new int[n]; for(int i = 0; i < n; i++) { d[i] = sc.nextInt(); } int p = (int)Math.pow(2, n); int[] kosuu = new int[p]; int[] dp = new int[p]; for(int i = 1; i < p; i++) { for(int j = 0; j < n; j++) { if(((i & (1 << j)) != 0) && (d[j] < 0)) kosuu[i]++; } } for(int i = 0; i < p; i++) { dp[i] = -1; } dp[0] = 0; for(int i = 1; i < p; i++) { for(int j = 0; j < n; j++) { if((i & (1 << j)) != 0) { int i1 = i - (1 << j); if(dp[i1] >= 0) { int t = dp[i1]; int max = 100 + kosuu[i1] * 100; if(d[j] > 0) { t = Math.min(t + d[j], max); } else { if((t + d[j]) >= 0) { t += d[j]; } else { t = -1; } } dp[i] = Math.max(dp[i], t); } } } } int ans = dp[p - 1]; if(dp[p - 1] == -1) ans = 0; System.out.println(ans); } }