結果

問題 No.266 最終進化を目指せ
ユーザー GrenacheGrenache
提出日時 2015-08-07 23:56:52
言語 Java21
(openjdk 21)
結果
AC  
実行時間 129 ms / 2,000 ms
コード長 1,316 bytes
コンパイル時間 3,354 ms
コンパイル使用メモリ 74,108 KB
実行使用メモリ 56,260 KB
最終ジャッジ日時 2023-09-25 06:30:17
合計ジャッジ時間 7,991 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
55,712 KB
testcase_01 AC 125 ms
55,404 KB
testcase_02 AC 124 ms
55,980 KB
testcase_03 AC 123 ms
55,660 KB
testcase_04 AC 122 ms
55,700 KB
testcase_05 AC 125 ms
55,644 KB
testcase_06 AC 126 ms
55,688 KB
testcase_07 AC 124 ms
55,440 KB
testcase_08 AC 126 ms
55,764 KB
testcase_09 AC 126 ms
55,504 KB
testcase_10 AC 128 ms
56,140 KB
testcase_11 AC 129 ms
55,988 KB
testcase_12 AC 128 ms
56,260 KB
testcase_13 AC 126 ms
55,864 KB
testcase_14 AC 126 ms
55,984 KB
testcase_15 AC 126 ms
55,640 KB
testcase_16 AC 124 ms
55,448 KB
testcase_17 AC 122 ms
53,652 KB
testcase_18 AC 124 ms
55,640 KB
testcase_19 AC 125 ms
55,984 KB
testcase_20 AC 122 ms
55,400 KB
testcase_21 AC 124 ms
55,984 KB
testcase_22 AC 122 ms
55,648 KB
testcase_23 AC 123 ms
55,812 KB
testcase_24 AC 127 ms
55,640 KB
testcase_25 AC 128 ms
56,040 KB
testcase_26 AC 128 ms
55,972 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;


public class Main_yukicoder266 {

	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        final int INF = Integer.MAX_VALUE / 2;
        int n = sc.nextInt();
        int[] s = new int[n + 1];
        for (int i = 0; i <= n; i++) {
        	s[i] = sc.nextInt();
        }

        int[][] dp = new int[n + 1][10 + 1];
        for (int i = 0; i <= n; i++) {
        	Arrays.fill(dp[i], INF);
        }
        dp[0][0] = 1;
        for (int i = 0; i <= n; i++) {
        	for (int j = 0; j <= 10; j++) {
        		if (j > s[i]) {
        			break;
        		}
        		if (i > 0) {
        			dp[i][j] = dp[i - 1][j] + 1;
        		}
        		for (int k = 0; k < j; k++) {
        			for (int l = 0; l < j; l++) {
        				if (j != s[n] && k + l + 1 == j) {
        					dp[i][j] = Math.min(dp[i][j], dp[i][k] + dp[i][l]);
        				} else if (j == s[n] && k + l + 1 >= j) {
        					dp[i][j] = Math.min(dp[i][j], dp[i][k] + dp[i][l]);
        				}
        			}
        		}
        	}
        }

        for (int i = 0; i <= s[n]; i++) {
        	if (i > 0) {
        		System.out.print(" ");
        	}
        	System.out.print(dp[n][i]);
        }
        System.out.println("");

        sc.close();
    }
}
0