結果

問題 No.15 カタログショッピング
ユーザー kou6839kou6839
提出日時 2014-11-16 13:53:51
言語 Java21
(openjdk 21)
結果
AC  
実行時間 486 ms / 5,000 ms
コード長 2,356 bytes
コンパイル時間 2,575 ms
コンパイル使用メモリ 86,916 KB
実行使用メモリ 78,056 KB
最終ジャッジ日時 2023-08-30 07:07:52
合計ジャッジ時間 6,594 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 162 ms
56,404 KB
testcase_01 AC 160 ms
56,640 KB
testcase_02 AC 164 ms
56,736 KB
testcase_03 AC 169 ms
56,500 KB
testcase_04 AC 159 ms
56,844 KB
testcase_05 AC 463 ms
76,868 KB
testcase_06 AC 486 ms
78,056 KB
testcase_07 AC 482 ms
76,936 KB
testcase_08 AC 485 ms
76,732 KB
testcase_09 AC 480 ms
76,500 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 S= sc.nextInt();
		ArrayList<Integer> p1 = new ArrayList<>();
		ArrayList<Integer> p2 = new ArrayList<>();
		HashMap<Integer,ArrayList<ArrayList<Integer>>> n1 = new HashMap<>();
		HashMap<Integer,ArrayList<ArrayList<Integer>>> n2 = new HashMap<>();
		for(int i=0;i<N/2;i++){
			p1.add(sc.nextInt());
		}
		for(int i=N/2;i<N;i++){
			p2.add(sc.nextInt());
		}
		/*for(int i=(1<<p1.size())-1;i>=0;i--){
			int sum=0;
			ArrayList<Integer> temp = new ArrayList<>();
			for(int j=0;j<p1.size();j++){
				if( (i<<j&1<<(p1.size()-1))==1<<(p1.size()-1)){
					sum+=p1.get(j);	
					temp.add(j+1);
				}
			}
		 if(!n1.containsKey(sum)) n1.put(sum,new ArrayList<ArrayList<Integer>>());
			n1.get(sum).add(temp);
		}*/
		for(int i=(1<<p2.size())-1;i>=0;i--){
			int sum=0;
			ArrayList<Integer> temp = new ArrayList<>();
			for(int j=0;j<p2.size();j++){
				if( (i<<j&1<<(p2.size()-1))==1<<(p2.size()-1)){
					sum+=p2.get(j);	
					temp.add(j+N/2+1);
				}
			}
			if(!n2.containsKey(sum)) n2.put(sum,new ArrayList<ArrayList<Integer>>());
			n2.get(sum).add(temp);
		}
		for(int i=(1<<p1.size())-1;i>=0;i--){
			int sum=0;
			ArrayList<Integer> temp = new ArrayList<>();
			for(int j=0;j<p1.size();j++){
				if( (i<<j&1<<(p1.size()-1))==1<<(p1.size()-1)){
					sum+=p1.get(j);	
					temp.add(j+1);
				}
			}
		if( n2.containsKey(S-sum) ){
		if(n2.get(S-sum)==null){
			String s ="";
			for(int ww:temp){
				s+=ww+" ";
			}
			System.out.println(s.trim());
		}else{
			for (ArrayList<Integer> g:n2.get(S-sum) ){
				String s ="";
				for(int ww:temp){
					s+=ww+" ";
				}
				for(int gg:g){
					s+=gg+" ";
				}
				System.out.println(s.trim());
			}
		}
			
		}
		}
		/*ArrayList<String> ans = new ArrayList<String>();
		for(int a:n1.keySet()){
			if(n2.containsKey(S-a)){
				for(ArrayList<Integer> f:n1.get(a)){
					for(ArrayList<Integer> g:n2.get(S-a)){
						String q ="";
						for(int r:f){
							q+=r+" ";
						}
						for(int t : g){
							q+=t+" ";
						}					
						ans.add(q.trim());
					}
				}
			}
		}
		Collections.sort(ans);
		for(String aa:ans){
			System.out.println(aa);
		}*/
	}
}	
0