結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 131 ms
57,636 KB
testcase_01 AC 128 ms
57,476 KB
testcase_02 WA -
testcase_03 AC 131 ms
57,424 KB
testcase_04 WA -
testcase_05 RE -
testcase_06 RE -
testcase_07 WA -
testcase_08 AC 140 ms
57,476 KB
testcase_09 AC 142 ms
57,456 KB
testcase_10 AC 143 ms
57,652 KB
testcase_11 AC 134 ms
57,464 KB
testcase_12 AC 133 ms
57,416 KB
testcase_13 AC 134 ms
57,456 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 RE -
testcase_19 RE -
testcase_20 AC 133 ms
57,436 KB
testcase_21 RE -
testcase_22 WA -
testcase_23 AC 140 ms
57,468 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 RE -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 160 ms
62,140 KB
testcase_39 AC 159 ms
62,140 KB
testcase_40 AC 124 ms
56,208 KB
testcase_41 RE -
testcase_42 AC 119 ms
56,312 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;
    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