結果
問題 | No.1199 お菓子配り-2 |
ユーザー |
![]() |
提出日時 | 2020-08-29 10:13:05 |
言語 | Java (openjdk 23) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,140 bytes |
コンパイル時間 | 2,388 ms |
コンパイル使用メモリ | 78,060 KB |
実行使用メモリ | 71,284 KB |
最終ジャッジ日時 | 2024-11-14 05:21:04 |
合計ジャッジ時間 | 64,197 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 14 TLE * 31 |
ソースコード
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]; } }