結果

問題 No.115 遠足のおやつ
ユーザー takeya_okinotakeya_okino
提出日時 2017-06-14 11:26:27
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,272 bytes
コンパイル時間 3,044 ms
コンパイル使用メモリ 77,816 KB
実行使用メモリ 62,432 KB
最終ジャッジ日時 2023-10-25 00:15:24
合計ジャッジ時間 10,731 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 131 ms
57,472 KB
testcase_01 AC 132 ms
57,552 KB
testcase_02 WA -
testcase_03 AC 128 ms
57,056 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 130 ms
57,712 KB
testcase_07 WA -
testcase_08 AC 130 ms
57,500 KB
testcase_09 AC 134 ms
57,136 KB
testcase_10 AC 136 ms
57,496 KB
testcase_11 AC 130 ms
57,392 KB
testcase_12 AC 130 ms
57,304 KB
testcase_13 AC 130 ms
57,552 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 129 ms
57,188 KB
testcase_19 WA -
testcase_20 AC 135 ms
57,444 KB
testcase_21 AC 131 ms
57,360 KB
testcase_22 WA -
testcase_23 AC 133 ms
57,436 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 168 ms
61,940 KB
testcase_39 AC 163 ms
62,432 KB
testcase_40 AC 134 ms
57,416 KB
testcase_41 AC 132 ms
57,412 KB
testcase_42 AC 135 ms
57,416 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];
    dp[N - 1][0][0] = 1;
    if(N < D + 1) dp[N - 1][N][1] = 1;
    for(int i = N - 2; i >= 0; i--) {
      dp[i][0][0] = 1;
      for(int j = 1; j < D + 1; j++) {
        for(int k = 1; k < K + 1; k++) {
          if(j >= (i + 1)) dp[i][j][k] = dp[i + 1][j - i - 1][k - 1];
        }
      }
    }
    boolean flg = false;
    for(int i = 0; i < N; i++) {
      if(dp[i][D][K] == 1) flg = true;
    }
    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] == 1) {
            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