結果

問題 No.15 カタログショッピング
ユーザー kou6839kou6839
提出日時 2014-11-16 03:07:20
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,547 bytes
コンパイル時間 2,486 ms
コンパイル使用メモリ 77,864 KB
実行使用メモリ 88,660 KB
最終ジャッジ日時 2023-08-30 07:06:14
合計ジャッジ時間 6,631 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 161 ms
56,508 KB
testcase_01 AC 155 ms
56,968 KB
testcase_02 AC 161 ms
56,860 KB
testcase_03 AC 164 ms
56,876 KB
testcase_04 AC 160 ms
56,624 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
権限があれば一括ダウンロードができます

ソースコード

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<>());
			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<>());
			n2.get(sum).add(temp);
		}

		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+" ";
						}
						System.out.println(q);
					}
				}
			}
		}		
	}
}
0