結果
問題 | No.572 妖精の演奏 |
ユーザー | tenten |
提出日時 | 2021-11-12 13:03:47 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 109 ms / 2,000 ms |
コード長 | 2,270 bytes |
コンパイル時間 | 2,249 ms |
コンパイル使用メモリ | 77,460 KB |
実行使用メモリ | 39,804 KB |
最終ジャッジ日時 | 2024-05-03 19:06:57 |
合計ジャッジ時間 | 4,565 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 53 ms
37,300 KB |
testcase_01 | AC | 52 ms
36,656 KB |
testcase_02 | AC | 55 ms
37,244 KB |
testcase_03 | AC | 57 ms
37,364 KB |
testcase_04 | AC | 54 ms
36,780 KB |
testcase_05 | AC | 68 ms
38,236 KB |
testcase_06 | AC | 67 ms
38,688 KB |
testcase_07 | AC | 63 ms
38,104 KB |
testcase_08 | AC | 62 ms
38,192 KB |
testcase_09 | AC | 66 ms
38,564 KB |
testcase_10 | AC | 101 ms
39,300 KB |
testcase_11 | AC | 97 ms
39,644 KB |
testcase_12 | AC | 106 ms
39,708 KB |
testcase_13 | AC | 109 ms
39,744 KB |
testcase_14 | AC | 98 ms
39,476 KB |
testcase_15 | AC | 98 ms
39,804 KB |
testcase_16 | AC | 90 ms
39,424 KB |
testcase_17 | AC | 106 ms
39,208 KB |
testcase_18 | AC | 67 ms
38,024 KB |
testcase_19 | AC | 49 ms
36,824 KB |
ソースコード
import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); long n = sc.nextLong() - 1; int m = sc.nextInt(); long[][][] dp = new long[33][m][m]; for (int i = 0; i < m; i++) { for (int j = 0; j < m; j++) { dp[0][i][j] = sc.nextInt(); } } for (int i = 1; i < 33; i++) { for (int j = 0; j < m; j++) { for (int k = 0; k < m; k++) { for (int l = 0; l < m; l++) { dp[i][j][k] = Math.max(dp[i][j][k], dp[i - 1][j][l] + dp[i - 1][l][k]); } } } } long[][] current = new long[m][m]; for (int i = 32; i >= 0; i--) { if (n < (1L << i)) { continue; } n -= (1L << i); long[][] next = new long[m][m]; for (int j = 0; j < m; j++) { for (int k = 0; k < m; k++) { for (int l = 0; l < m; l++) { next[j][k] = Math.max(next[j][k], current[j][l] + dp[i][l][k]); } } } current = next; } long max = 0; for (long[] arr : current) { for (long x : arr) { max = Math.max(max, x); } } System.out.println(max); } } 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(); } }