結果

問題 No.115 遠足のおやつ
ユーザー takeya_okinotakeya_okino
提出日時 2017-06-14 11:40:49
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,475 bytes
コンパイル時間 2,194 ms
コンパイル使用メモリ 78,084 KB
実行使用メモリ 69,992 KB
最終ジャッジ日時 2023-10-25 00:25:27
合計ジャッジ時間 9,715 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
57,052 KB
testcase_01 AC 138 ms
57,392 KB
testcase_02 AC 138 ms
57,172 KB
testcase_03 AC 141 ms
57,504 KB
testcase_04 WA -
testcase_05 AC 132 ms
57,144 KB
testcase_06 AC 132 ms
57,648 KB
testcase_07 AC 134 ms
57,672 KB
testcase_08 AC 134 ms
57,396 KB
testcase_09 AC 140 ms
59,644 KB
testcase_10 AC 146 ms
59,740 KB
testcase_11 AC 133 ms
57,352 KB
testcase_12 AC 135 ms
57,400 KB
testcase_13 AC 135 ms
57,436 KB
testcase_14 AC 133 ms
57,088 KB
testcase_15 AC 157 ms
60,104 KB
testcase_16 WA -
testcase_17 AC 154 ms
59,972 KB
testcase_18 AC 137 ms
57,648 KB
testcase_19 AC 137 ms
57,428 KB
testcase_20 AC 138 ms
57,224 KB
testcase_21 AC 134 ms
55,532 KB
testcase_22 AC 169 ms
59,964 KB
testcase_23 AC 133 ms
57,092 KB
testcase_24 AC 154 ms
60,068 KB
testcase_25 AC 152 ms
59,944 KB
testcase_26 AC 133 ms
57,352 KB
testcase_27 AC 137 ms
57,072 KB
testcase_28 AC 134 ms
57,352 KB
testcase_29 AC 140 ms
57,428 KB
testcase_30 AC 157 ms
59,940 KB
testcase_31 AC 135 ms
57,620 KB
testcase_32 AC 159 ms
62,448 KB
testcase_33 AC 133 ms
57,352 KB
testcase_34 WA -
testcase_35 AC 151 ms
60,140 KB
testcase_36 AC 153 ms
60,020 KB
testcase_37 WA -
testcase_38 AC 191 ms
69,988 KB
testcase_39 AC 195 ms
69,992 KB
testcase_40 AC 131 ms
57,444 KB
testcase_41 AC 132 ms
57,408 KB
testcase_42 AC 131 ms
57,108 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int D = sc.nextInt();
    int K = sc.nextInt();
    // dp[i][j][k]は最低金額(i+1)円,総額j円,個数k個の買い方があるかを表す
    int[][][] dp = new int[N][D + 1][K + 1];
    // sum[i][j][k] = dp[i][j][k] +...+dp[N - 1][j][k]
    int[][][] sum = new int[N][D + 1][K + 1];
    dp[N - 1][0][0] = 1;
    if(N < D + 1) dp[N - 1][N][1] = 1;
    sum[N - 1][0][0] = 1;
    if(N < D + 1) sum[N - 1][N][1] = 1;
    for(int i = N - 2; i >= 0; i--) {
      dp[i][0][0] = 1;
      sum[i][0][0] = 1 + sum[i + 1][0][0];
      for(int j = 1; j < D + 1; j++) {
        for(int k = 1; k < K + 1; k++) {
          if(j >= (i + 1)) dp[i][j][k] = sum[i + 1][j - i - 1][k - 1];
          sum[i][j][k] = dp[i][j][k] + sum[i + 1][j][k];
        }
      }
    }
    boolean flg = (sum[0][D][K] > 0);
    if(flg) {
      ArrayList<Integer> ans = new ArrayList<Integer>();
      int cost = D;
      int num = K;
      for(int i = 0; i < N; i++) {
        if(num > 0) {
          if(dp[i][cost][num] > 0) {
            ans.add(i + 1);
            cost -= (i + 1);
            num--;
          }
        } else {
          break;
        }
      }
      for(int i = 0; i < K; i++) {
        System.out.print(ans.get(i));
        if(i < K - 1) System.out.print(" ");
      }
    } else {
      System.out.println(-1);
    }
  }
}
0