結果
問題 | No.107 モンスター |
ユーザー | tenten |
提出日時 | 2021-11-10 11:11:45 |
言語 | Java21 (openjdk 21) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,875 bytes |
コンパイル時間 | 2,291 ms |
コンパイル使用メモリ | 77,784 KB |
実行使用メモリ | 58,540 KB |
最終ジャッジ日時 | 2024-04-30 22:22:49 |
合計ジャッジ時間 | 9,830 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 56 ms
50,352 KB |
testcase_01 | AC | 57 ms
50,408 KB |
testcase_02 | AC | 57 ms
50,404 KB |
testcase_03 | AC | 58 ms
50,404 KB |
testcase_04 | AC | 57 ms
50,036 KB |
testcase_05 | AC | 58 ms
50,348 KB |
testcase_06 | AC | 58 ms
50,240 KB |
testcase_07 | AC | 58 ms
49,976 KB |
testcase_08 | AC | 58 ms
50,272 KB |
testcase_09 | AC | 57 ms
50,392 KB |
testcase_10 | AC | 57 ms
50,452 KB |
testcase_11 | AC | 59 ms
50,416 KB |
testcase_12 | AC | 59 ms
50,412 KB |
testcase_13 | TLE | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
ソースコード
import java.util.*; import java.io.*; public class Main { static int ans = 0; static int n; static int[] monsters; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); n = sc.nextInt(); monsters = new int[n]; for (int i = 0; i < n; i++) { monsters[i] = sc.nextInt(); } check(0, 100, 100, new boolean[n]); System.out.println(ans); } static void check(int idx, int current, int max, boolean[] used) { if (idx >= n) { ans = Math.max(ans, current); return; } for (int i = 0; i < n; i++) { if (used[i]) { continue; } used[i] = true; if (monsters[i] < 0) { if (current + monsters[i] > 0) { check(idx + 1, current + monsters[i], max + 100, used); } } else { check(idx + 1, Math.min(current + monsters[i], max), max, used); } used[i] = false; } } } 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 nextLine() throws Exception { return br.readLine(); } public String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }