結果
| 問題 |
No.107 モンスター
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2021-11-10 11:11:45 |
| 言語 | Java (openjdk 23) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,875 bytes |
| コンパイル時間 | 2,307 ms |
| コンパイル使用メモリ | 77,608 KB |
| 実行使用メモリ | 75,244 KB |
| 最終ジャッジ日時 | 2024-11-20 20:39:56 |
| 合計ジャッジ時間 | 60,460 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 12 TLE * 9 |
ソースコード
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();
}
}
tenten