結果

問題 No.1199 お菓子配り-2
ユーザー tentententen
提出日時 2020-08-29 10:13:05
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,140 bytes
コンパイル時間 2,884 ms
コンパイル使用メモリ 77,396 KB
実行使用メモリ 62,988 KB
最終ジャッジ日時 2024-04-26 16:10:06
合計ジャッジ時間 38,575 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 111 ms
40,776 KB
testcase_01 AC 116 ms
41,184 KB
testcase_02 AC 108 ms
40,108 KB
testcase_03 AC 880 ms
57,320 KB
testcase_04 TLE -
testcase_05 AC 353 ms
47,380 KB
testcase_06 AC 458 ms
48,216 KB
testcase_07 TLE -
testcase_08 TLE -
testcase_09 AC 919 ms
57,080 KB
testcase_10 AC 546 ms
48,000 KB
testcase_11 AC 813 ms
55,440 KB
testcase_12 AC 796 ms
55,428 KB
testcase_13 AC 515 ms
47,864 KB
testcase_14 AC 494 ms
47,804 KB
testcase_15 AC 509 ms
48,272 KB
testcase_16 TLE -
testcase_17 AC 697 ms
57,196 KB
testcase_18 TLE -
testcase_19 AC 604 ms
48,044 KB
testcase_20 TLE -
testcase_21 TLE -
testcase_22 AC 943 ms
57,392 KB
testcase_23 TLE -
testcase_24 TLE -
testcase_25 AC 604 ms
48,356 KB
testcase_26 TLE -
testcase_27 TLE -
testcase_28 TLE -
testcase_29 TLE -
testcase_30 TLE -
testcase_31 TLE -
testcase_32 TLE -
testcase_33 TLE -
testcase_34 TLE -
testcase_35 TLE -
testcase_36 TLE -
testcase_37 TLE -
testcase_38 TLE -
testcase_39 TLE -
testcase_40 TLE -
testcase_41 TLE -
testcase_42 TLE -
testcase_43 TLE -
testcase_44 TLE -
testcase_45 TLE -
testcase_46 TLE -
testcase_47 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static long[] snacks;
    static long[][] dp;
	public static void main (String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
     	int m = sc.nextInt();
     	snacks = new long[n];
     	for (int i = 0; i < n; i++) {
     	    for (int j = 0; j < m; j++) {
     	        snacks[i] += sc.nextLong();
     	    }
     	}
     	dp = new long[n][2];
     	for (long[] arr : dp) {
     	    Arrays.fill(arr, Long.MIN_VALUE / 10);
     	}
     	System.out.println(Math.max(dfw(n - 1, 0), dfw(n - 1, 1)));
    }
    
    static long dfw(int idx, int evod) {
        if (idx < 0) {
            if (evod == 0) {
                return 0;
            } else {
                return Long.MIN_VALUE / 10;
            }
        }
        if (dp[idx][evod] == Long.MIN_VALUE / 10) {
            if (evod == 0) {
                dp[idx][evod] = Math.max(dfw(idx - 1, 0), dfw(idx - 1, 1) - snacks[idx]);
            } else {
                dp[idx][evod] = Math.max(dfw(idx - 1, 1), dfw(idx - 1, 0) + snacks[idx]);
            }
        }
        return dp[idx][evod];
    }
}
0