結果
| 問題 |
No.15 カタログショッピング
|
| コンテスト | |
| ユーザー |
夕叢霧香(ゆうむらきりか)
|
| 提出日時 | 2018-01-05 02:12:04 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,902 bytes |
| コンパイル時間 | 3,139 ms |
| コンパイル使用メモリ | 88,196 KB |
| 実行使用メモリ | 56,824 KB |
| 最終ジャッジ日時 | 2024-12-23 04:05:45 |
| 合計ジャッジ時間 | 5,619 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 4 WA * 6 |
ソースコード
import java.io.*;
import java.util.*;
class Main {
public static void main(String[] args) {
MyScanner sc = new MyScanner();
out = new PrintWriter(new BufferedOutputStream(System.out));
int n=sc.nextInt();
int s=sc.nextInt();
int[]p=sc.nextIntArray(n);
int m=n/2;
int[]f=new int[1<<m],snd=new int[1<<(n-m)];
for(int b=0;b<1<<m;++b)
for(int i=0;i<m;++i)
if((b&1<<i)!=0)
f[b]+=p[i];
for(int b=0;b<1<<(n-m);++b)
for(int i=0;i<n-m;++i)
if((b&1<<i)!=0)
snd[b]+=p[m+i];
Map<Integer,List<Integer>>hm=new HashMap<Integer,List<Integer>>();
for(int b=0;b<1<<(n-m);++b){
if(!hm.containsKey(snd[b]))
hm.put(snd[b],new ArrayList<Integer>());
hm.get(snd[b]).add(b);
}
List<Integer>ans=new ArrayList<Integer>();
for(int b=0;b<1<<m;++b){
if(hm.containsKey(s-f[b])){
for(int e:hm.get(s-f[b]))
ans.add(Integer.reverse(e<<m|b));
}
}
Collections.sort(ans);
Collections.reverse(ans);
for(int e:ans){
List<Integer>l=new ArrayList<Integer>();
for(int i=0;i<31;++i)
if((e&(1<<(31-i)))!=0)
l.add(i);
for(int i=0;i<l.size();++i)
out.print((l.get(i)+1)+(i==l.size()-1?"\n":" "));
}
out.close();
}
// http://codeforces.com/blog/entry/7018
//-----------PrintWriter for faster output---------------------------------
public static PrintWriter out;
//-----------MyScanner class for faster input----------
public static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine(){
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
int[] nextIntArray(int n){
int[]r=new int[n];
for(int i=0;i<n;++i)r[i]=nextInt();
return r;
}
}
}
夕叢霧香(ゆうむらきりか)