結果
問題 | No.90 品物の並び替え |
ユーザー | actu3 |
提出日時 | 2015-06-20 23:06:08 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 526 ms / 5,000 ms |
コード長 | 2,668 bytes |
コンパイル時間 | 3,669 ms |
コンパイル使用メモリ | 77,564 KB |
実行使用メモリ | 93,484 KB |
最終ジャッジ日時 | 2023-09-21 22:12:37 |
合計ジャッジ時間 | 6,445 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 81 ms
53,768 KB |
testcase_01 | AC | 290 ms
62,832 KB |
testcase_02 | AC | 79 ms
52,688 KB |
testcase_03 | AC | 169 ms
60,356 KB |
testcase_04 | AC | 174 ms
58,712 KB |
testcase_05 | AC | 281 ms
62,744 KB |
testcase_06 | AC | 309 ms
62,612 KB |
testcase_07 | AC | 105 ms
54,036 KB |
testcase_08 | AC | 88 ms
52,624 KB |
testcase_09 | AC | 526 ms
93,484 KB |
ソースコード
import java.io.InputStream; import java.io.InputStreamReader; import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.io.IOException; import java.util.*; public class Yuki90 { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); Solver solver = new Solver(); solver.solve(1, in, out); out.close(); } static class Solver { public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(); int m = in.nextInt(); int[] item1 = new int[m]; int[] item2 = new int[m]; int[] score = new int[m]; for (int i = 0; i < m; i++) { item1[i] = in.nextInt(); item2[i] = in.nextInt(); score[i] = in.nextInt(); } int[][] s = new int[n][n]; for (int i = 0; i < m; i++) { s[item1[i]][item2[i]] = score[i]; } StringBuilder sb = new StringBuilder(); for (int i = 0; i < n; i++) { sb.append(String.valueOf(i)); } makePermutation(sb.toString()); int max = 0; for (String str : perm) { int[] p = new int[n]; for (int i = 0; i < n; i++) { p[i] = Integer.valueOf(str.substring(i, i+1)); } int curscore = 0; for (int i = 0; i < n; i++) { for (int j = i+1; j < n; j++) { curscore += s[p[i]][p[j]]; } } max = Math.max(max, curscore); } System.out.println(max); } List<String> perm = new ArrayList<>(); public void makePermutation(String str) { permutation("", str); } private void permutation(String prefix, String str) { int n = str.length(); if (n == 0) perm.add(prefix); else { for (int i = 0; i < n; i++) permutation(prefix + str.charAt(i), str.substring(0, i) + str.substring(i+1, n)); } } } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } }