結果

問題 No.2095 High Rise
ユーザー tentententen
提出日時 2022-10-11 09:59:23
言語 Java21
(openjdk 21)
結果
AC  
実行時間 534 ms / 2,000 ms
コード長 1,765 bytes
コンパイル時間 3,455 ms
コンパイル使用メモリ 74,776 KB
実行使用メモリ 66,900 KB
最終ジャッジ日時 2023-09-07 11:36:01
合計ジャッジ時間 10,520 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,348 KB
testcase_01 AC 44 ms
49,372 KB
testcase_02 AC 43 ms
49,356 KB
testcase_03 AC 43 ms
49,492 KB
testcase_04 AC 44 ms
49,480 KB
testcase_05 AC 45 ms
47,212 KB
testcase_06 AC 45 ms
49,304 KB
testcase_07 AC 43 ms
49,344 KB
testcase_08 AC 43 ms
49,624 KB
testcase_09 AC 44 ms
49,304 KB
testcase_10 AC 44 ms
49,332 KB
testcase_11 AC 43 ms
49,148 KB
testcase_12 AC 67 ms
50,380 KB
testcase_13 AC 73 ms
51,276 KB
testcase_14 AC 92 ms
52,184 KB
testcase_15 AC 70 ms
50,560 KB
testcase_16 AC 61 ms
50,440 KB
testcase_17 AC 202 ms
57,168 KB
testcase_18 AC 172 ms
56,512 KB
testcase_19 AC 114 ms
51,976 KB
testcase_20 AC 206 ms
56,348 KB
testcase_21 AC 283 ms
60,120 KB
testcase_22 AC 485 ms
64,132 KB
testcase_23 AC 484 ms
63,956 KB
testcase_24 AC 475 ms
63,880 KB
testcase_25 AC 482 ms
63,836 KB
testcase_26 AC 534 ms
66,900 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int m = sc.nextInt();
        if (n == 1) {
            System.out.println(0);
            return;
        }
        long[][] dp = new long[n][m];
        for (int i = 0; i < m; i++) {
            dp[0][i] = sc.nextInt();
        }
        for (int i = 1; i < n; i++) {
            int[] values = new int[m];
            long min = Long.MAX_VALUE;
            for (int j = 0; j < m; j++) {
                values[j] = sc.nextInt();
                dp[i][j] = dp[i - 1][j] + values[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[j]);
            }
        }
        long ans = Long.MAX_VALUE;
        for (long x : dp[n - 1]) {
            ans = Math.min(ans, x);
        }
        System.out.println(ans);
    }
}
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 String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0