結果
問題 | No.2157 崖 |
ユーザー | tenten |
提出日時 | 2022-12-26 10:21:44 |
言語 | Java21 (openjdk 21) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,378 bytes |
コンパイル時間 | 3,711 ms |
コンパイル使用メモリ | 80,376 KB |
実行使用メモリ | 107,956 KB |
最終ジャッジ日時 | 2023-08-13 02:23:32 |
合計ジャッジ時間 | 15,008 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
49,872 KB |
testcase_01 | AC | 42 ms
49,648 KB |
testcase_02 | AC | 41 ms
49,248 KB |
testcase_03 | AC | 44 ms
49,452 KB |
testcase_04 | AC | 43 ms
49,120 KB |
testcase_05 | AC | 44 ms
49,460 KB |
testcase_06 | AC | 43 ms
49,160 KB |
testcase_07 | AC | 45 ms
49,384 KB |
testcase_08 | AC | 43 ms
49,440 KB |
testcase_09 | AC | 44 ms
49,256 KB |
testcase_10 | AC | 42 ms
47,236 KB |
testcase_11 | AC | 45 ms
49,384 KB |
testcase_12 | AC | 42 ms
49,624 KB |
testcase_13 | TLE | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
ソースコード
import java.io.*; import java.util.*; import java.util.stream.*; public class Main { static int[][] matrix; static ArrayList<HashMap<Integer, Integer>> dp = new ArrayList<>(); public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int m = sc.nextInt(); matrix = new int[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { matrix[i][j] = sc.nextInt(); } dp.add(new HashMap<>()); } int ans = Integer.MAX_VALUE; for (int i = 0; i < m; i++) { ans = Math.min(ans, dfw(n - 2, matrix[n - 1][i])); } if (ans >= Integer.MAX_VALUE / 2) { System.out.println(-1); } else { System.out.println(ans); } } static int dfw(int idx, int v) { if (idx < 0) { return 0; } if (!dp.get(idx).containsKey(v)) { int ans = Integer.MAX_VALUE / 2; for (int x : matrix[idx]) { if (x <= v) { ans = Math.min(ans, Math.max(dfw(idx - 1, x), v - x)); } } dp.get(idx).put(v, ans); } return dp.get(idx).get(v); } } class Utilities { static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); 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 int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }