結果

問題 No.1199 お菓子配り-2
ユーザー ks2mks2m
提出日時 2020-08-28 21:44:49
言語 Java21
(openjdk 21)
結果
AC  
実行時間 569 ms / 1,000 ms
コード長 953 bytes
コンパイル時間 2,363 ms
コンパイル使用メモリ 77,216 KB
実行使用メモリ 48,760 KB
最終ジャッジ日時 2024-04-26 14:38:56
合計ジャッジ時間 24,073 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
36,960 KB
testcase_01 AC 46 ms
37,100 KB
testcase_02 AC 45 ms
36,556 KB
testcase_03 AC 275 ms
45,604 KB
testcase_04 AC 427 ms
46,936 KB
testcase_05 AC 104 ms
40,528 KB
testcase_06 AC 135 ms
42,216 KB
testcase_07 AC 300 ms
46,424 KB
testcase_08 AC 334 ms
46,100 KB
testcase_09 AC 281 ms
46,648 KB
testcase_10 AC 168 ms
44,292 KB
testcase_11 AC 264 ms
45,060 KB
testcase_12 AC 233 ms
45,176 KB
testcase_13 AC 169 ms
44,276 KB
testcase_14 AC 163 ms
43,912 KB
testcase_15 AC 146 ms
43,752 KB
testcase_16 AC 339 ms
46,360 KB
testcase_17 AC 289 ms
45,644 KB
testcase_18 AC 372 ms
46,840 KB
testcase_19 AC 206 ms
44,840 KB
testcase_20 AC 440 ms
47,516 KB
testcase_21 AC 381 ms
46,640 KB
testcase_22 AC 295 ms
46,468 KB
testcase_23 AC 344 ms
46,556 KB
testcase_24 AC 397 ms
46,688 KB
testcase_25 AC 170 ms
42,940 KB
testcase_26 AC 388 ms
46,892 KB
testcase_27 AC 346 ms
46,072 KB
testcase_28 AC 487 ms
47,368 KB
testcase_29 AC 504 ms
47,420 KB
testcase_30 AC 537 ms
47,032 KB
testcase_31 AC 480 ms
47,608 KB
testcase_32 AC 534 ms
47,376 KB
testcase_33 AC 536 ms
47,016 KB
testcase_34 AC 530 ms
47,796 KB
testcase_35 AC 535 ms
48,052 KB
testcase_36 AC 523 ms
48,388 KB
testcase_37 AC 535 ms
48,324 KB
testcase_38 AC 569 ms
48,760 KB
testcase_39 AC 494 ms
48,120 KB
testcase_40 AC 501 ms
47,256 KB
testcase_41 AC 493 ms
48,452 KB
testcase_42 AC 478 ms
47,184 KB
testcase_43 AC 527 ms
47,296 KB
testcase_44 AC 525 ms
47,088 KB
testcase_45 AC 533 ms
47,428 KB
testcase_46 AC 536 ms
47,292 KB
testcase_47 AC 498 ms
47,388 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int m = Integer.parseInt(sa[1]);
		long[] a = new long[n];
		for (int i = 0; i < n; i++) {
			sa = br.readLine().split(" ");
			for (int j = 0; j < m; j++) {
				a[i] += Long.parseLong(sa[j]);
			}
		}
		br.close();

		long[][] dp = new long[2][n + 1];
		Arrays.fill(dp[0], Long.MIN_VALUE);
		Arrays.fill(dp[1], Long.MIN_VALUE);
		dp[0][0] = 0;
		dp[1][0] = 0;
		for (int i = 0; i < n; i++) {
			dp[0][i + 1] = dp[0][i];
			dp[1][i + 1] = dp[1][i];
			dp[1][i + 1] = Math.max(dp[1][i + 1], dp[0][i] + a[i]);
			dp[0][i + 1] = Math.max(dp[0][i + 1], dp[1][i] - a[i]);
		}
		System.out.println(Math.max(dp[0][n], dp[1][n]));
	}
}
0