結果
問題 |
No.15 カタログショッピング
|
ユーザー |
![]() |
提出日時 | 2014-11-16 03:05:05 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,556 bytes |
コンパイル時間 | 2,947 ms |
コンパイル使用メモリ | 86,876 KB |
実行使用メモリ | 83,000 KB |
最終ジャッジ日時 | 2024-12-31 20:32:46 |
合計ジャッジ時間 | 7,042 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 5 WA * 5 |
ソースコード
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); } } } } } }