結果
問題 | No.1117 数列分割 |
ユーザー | tenten |
提出日時 | 2020-08-18 06:47:07 |
言語 | Java21 (openjdk 21) |
結果 |
TLE
|
実行時間 | - |
コード長 | 958 bytes |
コンパイル時間 | 1,926 ms |
コンパイル使用メモリ | 77,828 KB |
実行使用メモリ | 82,524 KB |
最終ジャッジ日時 | 2024-04-20 00:12:12 |
合計ジャッジ時間 | 11,389 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 102 ms
60,076 KB |
testcase_01 | AC | 112 ms
53,900 KB |
testcase_02 | AC | 109 ms
52,752 KB |
testcase_03 | AC | 256 ms
59,592 KB |
testcase_04 | AC | 512 ms
59,716 KB |
testcase_05 | AC | 118 ms
54,064 KB |
testcase_06 | AC | 129 ms
54,056 KB |
testcase_07 | AC | 129 ms
54,396 KB |
testcase_08 | AC | 911 ms
59,908 KB |
testcase_09 | AC | 407 ms
57,048 KB |
testcase_10 | AC | 1,165 ms
59,676 KB |
testcase_11 | TLE | - |
testcase_12 | AC | 2,390 ms
74,700 KB |
testcase_13 | AC | 309 ms
82,524 KB |
testcase_14 | TLE | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
ソースコード
import java.util.*; public class Main { static int m; static int[] arr; static long[][] dp; public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); m = sc.nextInt(); arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = sc.nextInt(); } dp = new long[n][k]; System.out.println(dfw(n - 1, k - 1)); } static long dfw(int idx, int block) { if (idx < 0 && block < 0) { return 0; } if (block < 0) { return Long.MIN_VALUE; } if (dp[idx][block] != 0) { return dp[idx][block]; } long max = 0; long sum = 0; for (int i = 0; i < m && i <= idx - block; i++) { sum += arr[idx - i]; max = Math.max(max, Math.abs(sum) + dfw(idx - 1 - i, block - 1)); } dp[idx][block] = max; return max; } }