結果

問題 No.115 遠足のおやつ
ユーザー ぴろずぴろず
提出日時 2014-12-28 23:40:43
言語 Java21
(openjdk 21)
結果
AC  
実行時間 203 ms / 5,000 ms
コード長 1,129 bytes
コンパイル時間 2,641 ms
コンパイル使用メモリ 80,172 KB
実行使用メモリ 59,724 KB
最終ジャッジ日時 2023-08-31 00:20:46
合計ジャッジ時間 10,797 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
55,720 KB
testcase_01 AC 126 ms
55,668 KB
testcase_02 AC 130 ms
56,332 KB
testcase_03 AC 122 ms
55,628 KB
testcase_04 AC 200 ms
59,200 KB
testcase_05 AC 121 ms
56,092 KB
testcase_06 AC 122 ms
56,128 KB
testcase_07 AC 127 ms
55,848 KB
testcase_08 AC 123 ms
56,404 KB
testcase_09 AC 128 ms
55,904 KB
testcase_10 AC 129 ms
56,196 KB
testcase_11 AC 123 ms
56,108 KB
testcase_12 AC 122 ms
55,960 KB
testcase_13 AC 123 ms
55,564 KB
testcase_14 AC 133 ms
54,308 KB
testcase_15 AC 183 ms
59,724 KB
testcase_16 AC 198 ms
59,368 KB
testcase_17 AC 180 ms
58,696 KB
testcase_18 AC 123 ms
56,376 KB
testcase_19 AC 131 ms
55,436 KB
testcase_20 AC 136 ms
55,880 KB
testcase_21 AC 123 ms
55,728 KB
testcase_22 AC 179 ms
59,264 KB
testcase_23 AC 131 ms
55,888 KB
testcase_24 AC 182 ms
59,392 KB
testcase_25 AC 172 ms
58,500 KB
testcase_26 AC 148 ms
55,812 KB
testcase_27 AC 149 ms
58,116 KB
testcase_28 AC 145 ms
55,732 KB
testcase_29 AC 158 ms
58,288 KB
testcase_30 AC 179 ms
59,420 KB
testcase_31 AC 155 ms
56,024 KB
testcase_32 AC 182 ms
59,276 KB
testcase_33 AC 127 ms
55,652 KB
testcase_34 AC 186 ms
59,436 KB
testcase_35 AC 158 ms
58,896 KB
testcase_36 AC 175 ms
58,876 KB
testcase_37 AC 183 ms
59,272 KB
testcase_38 AC 203 ms
59,272 KB
testcase_39 AC 202 ms
59,156 KB
testcase_40 AC 122 ms
55,708 KB
testcase_41 AC 123 ms
56,004 KB
testcase_42 AC 120 ms
55,732 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package no115;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		int m = sc.nextInt();
		String[][][] dp = new String[2][m+1][d+1];
		dp[0][0][0] = "";
		int before = 0;
		int now = 1;
		for(int i=0;i<n;i++) {
			for(int j=0;j<=m;j++) {
				for(int k=0;k<=d;k++) {
					dp[now][j][k] = dp[before][j][k];
					if (j >= 1 && k >= i + 1 && dp[before][j-1][k-i-1] != null) {
						dp[now][j][k] = min(dp[now][j][k], dp[before][j-1][k-i-1].concat(String.valueOf((char) (i+1))));
					}
				}
			}
			before = 1 - before;
			now = 1 - now;
		}
		String ans = dp[before][m][d];
		if (ans == null) {
			System.out.println(-1);
			return;
		}
		StringBuilder sb = new StringBuilder();
		for(int i=0;i<ans.length();i++) {
			if (i > 0) {
				sb.append(' ');
			}
			sb.append((int) ans.charAt(i));
		}
		System.out.println(sb.toString());
	}

	static String min(String a,String b) {
		if (a == null) {
			return b;
		}else if(b == null) {
			return a;
		}else{
			return a.compareTo(b) < 0 ? a : b;
		}
	}

}
0