結果
問題 | No.324 落ちてた閉路グラフ |
ユーザー | Grenache |
提出日時 | 2015-12-18 16:13:15 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,382 bytes |
コンパイル時間 | 3,468 ms |
コンパイル使用メモリ | 75,092 KB |
実行使用メモリ | 54,652 KB |
最終ジャッジ日時 | 2023-10-14 13:59:54 |
合計ジャッジ時間 | 7,941 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
49,640 KB |
testcase_01 | AC | 40 ms
49,488 KB |
testcase_02 | AC | 39 ms
49,468 KB |
testcase_03 | AC | 40 ms
49,288 KB |
testcase_04 | AC | 136 ms
50,800 KB |
testcase_05 | AC | 200 ms
52,680 KB |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | AC | 122 ms
53,368 KB |
testcase_09 | WA | - |
testcase_10 | AC | 122 ms
52,796 KB |
testcase_11 | WA | - |
testcase_12 | RE | - |
testcase_13 | AC | 49 ms
51,180 KB |
testcase_14 | AC | 88 ms
52,652 KB |
testcase_15 | AC | 101 ms
53,264 KB |
testcase_16 | RE | - |
testcase_17 | AC | 39 ms
49,360 KB |
testcase_18 | AC | 38 ms
49,460 KB |
testcase_19 | AC | 38 ms
49,576 KB |
testcase_20 | RE | - |
testcase_21 | AC | 40 ms
49,496 KB |
testcase_22 | AC | 40 ms
49,484 KB |
testcase_23 | AC | 41 ms
49,536 KB |
testcase_24 | RE | - |
testcase_25 | WA | - |
testcase_26 | AC | 38 ms
49,332 KB |
testcase_27 | AC | 38 ms
49,512 KB |
testcase_28 | AC | 37 ms
49,424 KB |
testcase_29 | RE | - |
testcase_30 | AC | 38 ms
49,364 KB |
testcase_31 | AC | 38 ms
49,360 KB |
testcase_32 | AC | 200 ms
52,928 KB |
testcase_33 | AC | 173 ms
52,832 KB |
testcase_34 | WA | - |
testcase_35 | AC | 46 ms
49,424 KB |
testcase_36 | WA | - |
testcase_37 | WA | - |
ソースコード
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.Iterator; public class Main_yukicoder324_1 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Printer pr = new Printer(System.out); final int INF = Integer.MAX_VALUE / 2; int n = sc.nextInt(); int m = sc.nextInt(); int[] w = new int[n]; for (int i = 0; i < n; i++) { w[i] = sc.nextInt(); } int[][][] dp = new int[2][m + 1][2]; int[][][] dp2 = new int[2][m + 1][2]; for (int i = 0; i < 2; i++) { for (int j = 0; j <= m; j++) { Arrays.fill(dp[i][j], -INF); Arrays.fill(dp2[i][j], -INF); } } for (int i = 0; i < 2; i++) { dp[i][0][0] = 0; } dp2[0][1][1] = 0; for (int i = 1; i < n; i++) { int tmpi = i % 2; int tmpim = (i + 1) % 2; for (int j = 1; j <= m; j++) { if (i != n - 1) { dp[tmpi][j][0] = Math.max(dp[tmpi][j][0], Math.max(dp[tmpim][j][0], dp[tmpim][j][1])); dp[tmpi][j][1] = Math.max(dp[tmpi][j][1], Math.max(dp[tmpim][j - 1][0], dp[tmpim][j - 1][1] + w[i - 1])); dp2[tmpi][j][0] = Math.max(dp2[tmpi][j][0], Math.max(dp2[tmpim][j][0], dp2[tmpim][j][1])); dp2[tmpi][j][1] = Math.max(dp2[tmpi][j][1], Math.max(dp2[tmpim][j - 1][0], dp2[tmpim][j - 1][1] + w[i - 1])); } else { dp[tmpi][j][0] = Math.max(dp[tmpi][j][0], Math.max(dp[tmpim][j][0], dp[tmpim][j][1])); dp[tmpi][j][1] = Math.max(dp[tmpi][j][1], Math.max(dp[tmpim][j - 1][0], dp[tmpim][j - 1][1] + w[i - 1])); dp2[tmpi][j][0] = Math.max(dp2[tmpi][j][0], Math.max(dp2[tmpim][j][0], dp2[tmpim][j][1])); dp2[tmpi][j][1] = Math.max(dp2[tmpi][j][1], Math.max(dp2[tmpim][j - 1][0] + w[i], dp2[tmpim][j - 1][1] + w[i - 1] + w[i])); } } } int max = -INF; for (int i = 0; i < 2; i++) { max = Math.max(max, dp[(n - 1) % 2][m][i]); max = Math.max(max, dp2[(n - 1) % 2][m][i]); } pr.println(max); pr.close(); sc.close(); } @SuppressWarnings("unused") private static class Scanner { BufferedReader br; Iterator<String> it; Scanner (InputStream in) { br = new BufferedReader(new InputStreamReader(in)); } String next() throws RuntimeException { try { if (it == null || !it.hasNext()) { it = Arrays.asList(br.readLine().split(" ")).iterator(); } return it.next(); } catch (IOException e) { throw new IllegalStateException(); } } int nextInt() throws RuntimeException { return Integer.parseInt(next()); } long nextLong() throws RuntimeException { return Long.parseLong(next()); } float nextFloat() throws RuntimeException { return Float.parseFloat(next()); } double nextDouble() throws RuntimeException { return Double.parseDouble(next()); } void close() { try { br.close(); } catch (IOException e) { // throw new IllegalStateException(); } } } private static class Printer extends PrintWriter { Printer(PrintStream out) { super(out); } } }