結果

問題 No.115 遠足のおやつ
ユーザー chiho_miyako
提出日時 2015-04-16 19:02:40
言語 Java
(openjdk 23)
結果
RE  
実行時間 -
コード長 1,355 bytes
コンパイル時間 2,487 ms
コンパイル使用メモリ 80,512 KB
実行使用メモリ 102,324 KB
最終ジャッジ日時 2024-07-04 14:59:32
合計ジャッジ時間 11,868 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 31 RE * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
   public static void main(String[] args) throws Exception {
       Scanner koko = new Scanner(System.in);
       int n = koko.nextInt();
       int d = koko.nextInt();
       int k = koko.nextInt();
       boolean[][][] price = new boolean[n+1][n+1][n*(n+1)/2];
       price[0][0][0]=true;
       for(int x=0; x<n; x++){
           for(int y=0; y<=x; y++){
               for(int z=0; z<d+1; z++){
                   if(price[x][y][z]){
                       price[x+1][y][z]=true;
                       price[x+1][y+1][z+x+1]=true;
                   }
               }
           }
       }
       boolean judge = false;
       for(int x=n; x>0; x--){
           if(price[x][k][d]){
               judge=true;
               int[] a = new int[k];
               int b =0;
               while(x>0){
                   if(x<=d&&price[x-1][k-1][d-x]){
                       a[b++]=x;
                       k--;
                       d=d-x;
                       x--;
                   }else{
                       x--;
                   }
               }
               Arrays.sort(a);
               for(int i=0; i<b; i++){
                   System.out.print(a[i]+" ");
               }
               break;
           }
       }
       if(!judge){
           System.out.println(-1);
       }
    }
}
0