結果

問題 No.115 遠足のおやつ
ユーザー threepipes_sthreepipes_s
提出日時 2016-01-03 18:40:06
言語 Java21
(openjdk 21)
結果
AC  
実行時間 108 ms / 5,000 ms
コード長 3,183 bytes
コンパイル時間 2,678 ms
コンパイル使用メモリ 87,632 KB
実行使用メモリ 55,840 KB
最終ジャッジ日時 2023-08-31 00:36:48
合計ジャッジ時間 7,140 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
49,224 KB
testcase_01 AC 43 ms
49,528 KB
testcase_02 AC 69 ms
51,480 KB
testcase_03 AC 42 ms
49,616 KB
testcase_04 AC 97 ms
55,484 KB
testcase_05 AC 65 ms
51,988 KB
testcase_06 AC 42 ms
49,484 KB
testcase_07 AC 67 ms
50,840 KB
testcase_08 AC 43 ms
49,492 KB
testcase_09 AC 44 ms
49,544 KB
testcase_10 AC 44 ms
49,460 KB
testcase_11 AC 43 ms
49,472 KB
testcase_12 AC 44 ms
49,544 KB
testcase_13 AC 44 ms
49,584 KB
testcase_14 AC 70 ms
51,156 KB
testcase_15 AC 85 ms
54,936 KB
testcase_16 AC 88 ms
54,616 KB
testcase_17 AC 78 ms
52,600 KB
testcase_18 AC 43 ms
49,580 KB
testcase_19 AC 67 ms
51,000 KB
testcase_20 AC 70 ms
51,432 KB
testcase_21 AC 68 ms
50,928 KB
testcase_22 AC 87 ms
54,580 KB
testcase_23 AC 47 ms
49,880 KB
testcase_24 AC 84 ms
52,792 KB
testcase_25 AC 75 ms
52,044 KB
testcase_26 AC 72 ms
51,104 KB
testcase_27 AC 77 ms
52,292 KB
testcase_28 AC 73 ms
51,044 KB
testcase_29 AC 74 ms
51,472 KB
testcase_30 AC 86 ms
53,228 KB
testcase_31 AC 76 ms
50,972 KB
testcase_32 AC 105 ms
55,840 KB
testcase_33 AC 69 ms
50,912 KB
testcase_34 AC 98 ms
55,564 KB
testcase_35 AC 84 ms
52,224 KB
testcase_36 AC 84 ms
52,532 KB
testcase_37 AC 85 ms
54,356 KB
testcase_38 AC 108 ms
55,824 KB
testcase_39 AC 82 ms
54,804 KB
testcase_40 AC 43 ms
49,604 KB
testcase_41 AC 44 ms
49,476 KB
testcase_42 AC 67 ms
50,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.BitSet;
import java.util.HashMap;

public class Main {
	public static void main(String[] args) throws NumberFormatException,
	IOException {Solve solve = new Solve();solve.solve();}
}
class Solve{
	void dump(int[]a){for(int i=0;i<a.length;i++)System.out.print(a[i]+" ");System.out.println();};
	void solve() throws NumberFormatException, IOException{
		final ContestScanner in = new ContestScanner();
		Writer out = new Writer();
		int n = in.nextInt();
		int d = in.nextInt();
		int k = in.nextInt();
		if(k>n){
			System.out.println(-1);
			return;
		}
		BitSet[][] dp = new BitSet[k+1][d+1];
		dp[0][0] = new BitSet(n);
		for(int i=n-1; i>=0; i--){
			final int v = i+1;
			for(int j=k-1; j>=0; j--){
				for(int l=0; l<=d-v; l++){
					if(dp[j][l]==null) continue;
					dp[j+1][l+v] = (BitSet) dp[j][l].clone();
					dp[j+1][l+v].set(v);
				}
			}
		}
		if(dp[k][d]==null) System.out.println(-1);
		else{
			StringBuilder sb = new StringBuilder();
			BitSet bs = dp[k][d];
			for(int i=bs.nextSetBit(0); i!=-1; i=bs.nextSetBit(i+1)){
				sb.append(i+" ");
			}
			System.out.println(sb.toString().trim());
		}
	}
}

class MultiSet<T> extends HashMap<T, Integer>{
	@Override
	public Integer get(Object key){return containsKey(key)?super.get(key):0;}
	public void add(T key,int v){put(key,get(key)+v);}
	public void add(T key){put(key,get(key)+1);}
	public void sub(T key)
	{final int v=get(key);if(v==1)remove(key);else put(key,v-1);}
}
class Timer{
	long time;
	public void set(){time=System.currentTimeMillis();}
	public long stop(){return time=System.currentTimeMillis()-time;}
	public void print()
	{System.out.println("Time: "+(System.currentTimeMillis()-time)+"ms");}
	@Override public String toString(){return"Time: "+time+"ms";}
}
class Writer extends PrintWriter{
	public Writer(String filename)throws IOException
	{super(new BufferedWriter(new FileWriter(filename)));}
	public Writer()throws IOException{super(System.out);}
}
class ContestScanner {
	private InputStreamReader in;private int c=-2;
	public ContestScanner()throws IOException 
	{in=new InputStreamReader(System.in);}
	public ContestScanner(String filename)throws IOException
	{in=new InputStreamReader(new FileInputStream(filename));}
	public String nextToken()throws IOException {
		StringBuilder sb=new StringBuilder();
		while((c=in.read())!=-1&&Character.isWhitespace(c));
		while(c!=-1&&!Character.isWhitespace(c)){sb.append((char)c);c=in.read();}
		return sb.toString();
	}
	public String readLine()throws IOException{
		StringBuilder sb=new StringBuilder();if(c==-2)c=in.read();
		while(c!=-1&&c!='\n'&&c!='\r'){sb.append((char)c);c=in.read();}
		return sb.toString();
	}
	public long nextLong()throws IOException,NumberFormatException
	{return Long.parseLong(nextToken());}
	public int nextInt()throws NumberFormatException,IOException
	{return(int)nextLong();}
	public double nextDouble()throws NumberFormatException,IOException 
	{return Double.parseDouble(nextToken());}
}
0