結果
問題 | No.90 品物の並び替え |
ユーザー | tenten |
提出日時 | 2022-07-28 18:56:04 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 303 ms / 5,000 ms |
コード長 | 1,922 bytes |
コンパイル時間 | 5,278 ms |
コンパイル使用メモリ | 75,384 KB |
実行使用メモリ | 57,476 KB |
最終ジャッジ日時 | 2023-09-25 11:54:13 |
合計ジャッジ時間 | 4,301 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 44 ms
49,344 KB |
testcase_01 | AC | 146 ms
57,128 KB |
testcase_02 | AC | 43 ms
49,408 KB |
testcase_03 | AC | 81 ms
52,196 KB |
testcase_04 | AC | 82 ms
52,700 KB |
testcase_05 | AC | 176 ms
56,780 KB |
testcase_06 | AC | 135 ms
57,476 KB |
testcase_07 | AC | 58 ms
51,128 KB |
testcase_08 | AC | 44 ms
49,168 KB |
testcase_09 | AC | 303 ms
57,280 KB |
ソースコード
import java.io.*; import java.util.*; public class Main { static ArrayList<HashMap<Integer, Integer>> scores = new ArrayList<>(); static int max = 0; static int n; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); n = sc.nextInt(); int m = sc.nextInt(); for (int i = 0; i < n; i++) { scores.add(new HashMap<>()); } for (int i = 0; i < m; i++) { int a = sc.nextInt(); int b = sc.nextInt(); scores.get(b).put(a, sc.nextInt()); } check(0, new boolean[n], 0); System.out.println(max); } static void check(int idx, boolean[] used, int value) { if (idx >= n) { max = Math.max(max, value); return; } for (int i = 0; i < n; i++) { if (used[i]) { continue; } used[i] = true; int tmp = 0; for (int x : scores.get(i).keySet()) { if (used[x]) { tmp += scores.get(i).get(x); } } check(idx + 1, used, value + tmp); 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 next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }