結果
問題 | No.1199 お菓子配り-2 |
ユーザー | shojin_pro |
提出日時 | 2020-08-28 22:12:16 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 573 ms / 1,000 ms |
コード長 | 3,296 bytes |
コンパイル時間 | 2,430 ms |
コンパイル使用メモリ | 79,196 KB |
実行使用メモリ | 68,604 KB |
最終ジャッジ日時 | 2024-11-14 03:34:53 |
合計ジャッジ時間 | 25,213 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 53 ms
50,504 KB |
testcase_01 | AC | 53 ms
50,276 KB |
testcase_02 | AC | 53 ms
50,484 KB |
testcase_03 | AC | 304 ms
59,504 KB |
testcase_04 | AC | 465 ms
66,396 KB |
testcase_05 | AC | 127 ms
52,620 KB |
testcase_06 | AC | 146 ms
54,448 KB |
testcase_07 | AC | 336 ms
58,132 KB |
testcase_08 | AC | 371 ms
59,712 KB |
testcase_09 | AC | 307 ms
57,536 KB |
testcase_10 | AC | 184 ms
55,592 KB |
testcase_11 | AC | 281 ms
57,392 KB |
testcase_12 | AC | 275 ms
56,528 KB |
testcase_13 | AC | 179 ms
55,164 KB |
testcase_14 | AC | 170 ms
56,484 KB |
testcase_15 | AC | 157 ms
55,192 KB |
testcase_16 | AC | 361 ms
59,324 KB |
testcase_17 | AC | 302 ms
59,708 KB |
testcase_18 | AC | 420 ms
66,380 KB |
testcase_19 | AC | 234 ms
59,072 KB |
testcase_20 | AC | 476 ms
66,324 KB |
testcase_21 | AC | 432 ms
66,220 KB |
testcase_22 | AC | 374 ms
65,372 KB |
testcase_23 | AC | 424 ms
66,408 KB |
testcase_24 | AC | 431 ms
66,376 KB |
testcase_25 | AC | 183 ms
54,896 KB |
testcase_26 | AC | 421 ms
61,800 KB |
testcase_27 | AC | 382 ms
59,272 KB |
testcase_28 | AC | 573 ms
68,604 KB |
testcase_29 | AC | 530 ms
67,160 KB |
testcase_30 | AC | 541 ms
66,808 KB |
testcase_31 | AC | 530 ms
67,044 KB |
testcase_32 | AC | 536 ms
67,536 KB |
testcase_33 | AC | 489 ms
64,408 KB |
testcase_34 | AC | 538 ms
67,156 KB |
testcase_35 | AC | 537 ms
66,720 KB |
testcase_36 | AC | 541 ms
66,692 KB |
testcase_37 | AC | 541 ms
66,600 KB |
testcase_38 | AC | 533 ms
66,816 KB |
testcase_39 | AC | 563 ms
67,744 KB |
testcase_40 | AC | 530 ms
67,192 KB |
testcase_41 | AC | 547 ms
67,512 KB |
testcase_42 | AC | 529 ms
66,496 KB |
testcase_43 | AC | 535 ms
66,548 KB |
testcase_44 | AC | 541 ms
67,552 KB |
testcase_45 | AC | 541 ms
67,108 KB |
testcase_46 | AC | 527 ms
67,440 KB |
testcase_47 | AC | 541 ms
66,720 KB |
ソースコード
import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws Exception { FastScanner sc = new FastScanner(System.in); PrintWriter pw = new PrintWriter(System.out); int n = sc.nextInt(); int m = sc.nextInt(); long[][] dp = new long[n+1][n+1]; for(int i = 0; i < n; i++){ Arrays.fill(dp[i],-Long.MAX_VALUE/2); } dp[0][0] = 0; for(int i = 0; i < n; i++){ long total = 0; for(int j = 0; j < m; j++){ total += sc.nextLong(); } for(int j = 0; j <= i; j++){ dp[i+1][j] = Math.max(dp[i+1][j],dp[i][j]); if(j % 2 == 0){ dp[i+1][j+1] = Math.max(dp[i+1][j+1],dp[i][j] + total); }else{ dp[i+1][j+1] = Math.max(dp[i+1][j+1],dp[i][j] - total); } } } long ans = 0; for(int i = 0; i <= n; i++){ ans = Math.max(ans,dp[n][i]); } pw.println(ans); pw.flush(); } static class GeekInteger { public static void save_sort(int[] array) { shuffle(array); Arrays.sort(array); } public static int[] shuffle(int[] array) { int n = array.length; Random random = new Random(); for (int i = 0, j; i < n; i++) { j = i + random.nextInt(n - i); int randomElement = array[j]; array[j] = array[i]; array[i] = randomElement; } return array; } } } class FastScanner { private BufferedReader reader = null; private StringTokenizer tokenizer = null; public FastScanner(InputStream in) { reader = new BufferedReader(new InputStreamReader(in)); tokenizer = null; } public String next() { if (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public String nextLine() { if (tokenizer == null || !tokenizer.hasMoreTokens()) { try { return reader.readLine(); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken("\n"); } public long nextLong() { return Long.parseLong(next()); } public int nextInt() { return Integer.parseInt(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String[] nextArray(int n) { String[] a = new String[n]; for (int i = 0; i < n; i++) a[i] = next(); return a; } public int[] nextIntArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public long[] nextLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } }