結果
問題 | No.90 品物の並び替え |
ユーザー | actu3 |
提出日時 | 2015-06-20 23:06:08 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 622 ms / 5,000 ms |
コード長 | 2,668 bytes |
コンパイル時間 | 3,942 ms |
コンパイル使用メモリ | 80,724 KB |
実行使用メモリ | 82,024 KB |
最終ジャッジ日時 | 2024-07-07 15:21:40 |
合計ジャッジ時間 | 6,987 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 88 ms
38,664 KB |
testcase_01 | AC | 323 ms
50,940 KB |
testcase_02 | AC | 88 ms
38,244 KB |
testcase_03 | AC | 183 ms
46,700 KB |
testcase_04 | AC | 186 ms
46,296 KB |
testcase_05 | AC | 331 ms
50,816 KB |
testcase_06 | AC | 340 ms
50,880 KB |
testcase_07 | AC | 122 ms
40,064 KB |
testcase_08 | AC | 90 ms
38,200 KB |
testcase_09 | AC | 622 ms
82,024 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()); } } }