結果

問題 No.2095 High Rise
ユーザー tentententen
提出日時 2024-04-30 13:55:01
言語 Java21
(openjdk 21)
結果
AC  
実行時間 586 ms / 2,000 ms
コード長 1,997 bytes
コンパイル時間 2,493 ms
コンパイル使用メモリ 78,868 KB
実行使用メモリ 67,328 KB
最終ジャッジ日時 2024-04-30 13:55:12
合計ジャッジ時間 10,559 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
51,108 KB
testcase_01 AC 66 ms
51,140 KB
testcase_02 AC 54 ms
50,012 KB
testcase_03 AC 67 ms
51,280 KB
testcase_04 AC 66 ms
51,220 KB
testcase_05 AC 66 ms
51,036 KB
testcase_06 AC 67 ms
51,208 KB
testcase_07 AC 66 ms
51,232 KB
testcase_08 AC 55 ms
50,420 KB
testcase_09 AC 54 ms
50,136 KB
testcase_10 AC 66 ms
51,196 KB
testcase_11 AC 67 ms
51,136 KB
testcase_12 AC 94 ms
52,200 KB
testcase_13 AC 91 ms
51,540 KB
testcase_14 AC 111 ms
52,432 KB
testcase_15 AC 98 ms
51,880 KB
testcase_16 AC 90 ms
51,928 KB
testcase_17 AC 250 ms
57,160 KB
testcase_18 AC 243 ms
57,312 KB
testcase_19 AC 156 ms
54,040 KB
testcase_20 AC 253 ms
57,304 KB
testcase_21 AC 318 ms
58,252 KB
testcase_22 AC 545 ms
65,576 KB
testcase_23 AC 529 ms
65,968 KB
testcase_24 AC 586 ms
67,328 KB
testcase_25 AC 582 ms
67,196 KB
testcase_26 AC 537 ms
65,840 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        if (n == 1) {
            System.out.println(0);
            return;
        }
        int m = sc.nextInt();
        int[][] values = new int[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                values[i][j] = sc.nextInt();
            }
        }
        long[][] dp = new long[n][m];
        for (int i = 0; i < m; i++) {
            dp[0][i] = values[0][i];
        }
        for (int i = 1; i < n; i++) {
            long min = Long.MAX_VALUE;
            for (int j = 0; j < m; j++) {
                dp[i][j] = dp[i - 1][j] + values[i][j];
                min = Math.min(min, dp[i][j]);
            }
            for (int j = 0; j < m; j++) {
                dp[i][j] = Math.min(dp[i][j], min + values[i][j]);
            }
        }
        long ans = Arrays.stream(dp[n - 1]).min().orElse(0L);
        System.out.println(ans);
    }
}
class Scanner {
    BufferedReader br;
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
        } catch (Exception e) {
            
        }
    }
    
    public int nextInt() {
        return Integer.parseInt(next());
    }
    
    public long nextLong() {
        return Long.parseLong(next());
    }
    
    public double nextDouble() {
        return Double.parseDouble(next());
    }
    
    public String next() {
        try {
            while (!st.hasMoreTokens()) {
                st = new StringTokenizer(br.readLine());
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            return st.nextToken();
        }
    }
    
}
0