結果

問題 No.107 モンスター
ユーザー tentententen
提出日時 2021-11-10 11:11:45
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,875 bytes
コンパイル時間 4,122 ms
コンパイル使用メモリ 74,000 KB
実行使用メモリ 78,384 KB
最終ジャッジ日時 2023-08-13 03:59:21
合計ジャッジ時間 11,759 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
53,688 KB
testcase_01 AC 43 ms
49,332 KB
testcase_02 AC 43 ms
49,028 KB
testcase_03 AC 43 ms
49,096 KB
testcase_04 AC 43 ms
49,500 KB
testcase_05 AC 43 ms
49,324 KB
testcase_06 AC 42 ms
49,128 KB
testcase_07 AC 43 ms
49,156 KB
testcase_08 AC 43 ms
49,296 KB
testcase_09 AC 43 ms
49,188 KB
testcase_10 AC 42 ms
49,252 KB
testcase_11 AC 43 ms
49,104 KB
testcase_12 AC 44 ms
49,360 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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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();
    }
}
0