結果

問題 No.266 最終進化を目指せ
ユーザー yuki2006yuki2006
提出日時 2015-08-06 17:16:44
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,325 bytes
コンパイル時間 3,316 ms
コンパイル使用メモリ 74,632 KB
実行使用メモリ 57,720 KB
最終ジャッジ日時 2023-09-25 04:11:27
合計ジャッジ時間 8,270 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 127 ms
55,752 KB
testcase_02 AC 127 ms
55,840 KB
testcase_03 WA -
testcase_04 AC 126 ms
55,948 KB
testcase_05 AC 121 ms
55,876 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 124 ms
55,424 KB
testcase_14 AC 127 ms
55,824 KB
testcase_15 WA -
testcase_16 AC 128 ms
55,896 KB
testcase_17 WA -
testcase_18 AC 125 ms
55,532 KB
testcase_19 AC 121 ms
55,864 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 127 ms
55,716 KB
testcase_23 AC 123 ms
55,960 KB
testcase_24 AC 126 ms
55,808 KB
testcase_25 WA -
testcase_26 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Yuki_596 {

    int MOD = 1000000007;


    public Yuki_596() {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] S = new int[N + 1];
        for (int i = 0; i <= N; i++) {
            S[i] = scanner.nextInt();
        }
        int T = S[S.length - 1] + 1;

        int[][] dp = new int[N + 2][T];
        for (int i = 1; i <= N; i++) {
            dp[i][0] = i + 1;
        }
        for (int i = 0; i < T; i++) {
            dp[0][i] = i + 1;
        }

        for (int i = 1; i <= N; i++) {
            for (int j = 1; j <= T; j++) {
                if (j > S[i]) {
                    continue;
                }
                dp[i][j] = dp[i][0] + dp[i][j - 1];
                for (int k = 0; k < j; k++) {
                    dp[i][j] = Math.min(dp[i][j], dp[i][k] + dp[i][j - k - 1]);
                }

                if (dp[i - 1][j] > 0) {
                    dp[i][j] = Math.min(dp[i][j], dp[i - 1][j] + 1);
                }
            }
        }

        for (int i = 0; i < T; i++) {
            if (i >= 1) {
                System.out.print(" ");
            }
            System.out.print(dp[N][i]);
        }

    }


    public static void main(String[] args) {
        Yuki_596 hoge = new Yuki_596();
    }
}
0