結果
問題 |
No.332 数列をプレゼントに
|
ユーザー |
|
提出日時 | 2015-12-25 22:33:25 |
言語 | Java (openjdk 23) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,763 bytes |
コンパイル時間 | 4,402 ms |
コンパイル使用メモリ | 80,688 KB |
実行使用メモリ | 525,720 KB |
最終ジャッジ日時 | 2024-09-19 00:04:07 |
合計ジャッジ時間 | 8,095 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | RE * 2 MLE * 1 -- * 39 |
ソースコード
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintStream; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; public class Main_yukicoder332 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Printer pr = new Printer(System.out); int n = sc.nextInt(); long x = sc.nextLong(); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = sc.nextInt(); } Map<Long, List<Integer>> hm = new HashMap<Long, List<Integer>>(); hm.put(0L, new ArrayList<Integer>()); for (int i = 0; i < n; i++) { Map<Long, List<Integer>> hm2 = new HashMap<Long, List<Integer>>(); for (Entry<Long, List<Integer>> e : hm.entrySet()) { if (e.getKey() + a[i] <= x && !hm.containsKey(e.getKey() + a[i])) { ArrayList<Integer> tmp = new ArrayList<Integer>(e.getValue()); tmp.add(i); hm2.put(e.getKey() + a[i], tmp); } } hm.putAll(hm2); } if (hm.containsKey(x)) { List<Integer> ret = hm.get(x); int j = 0; StringBuilder tmp = new StringBuilder(); for (int i = 0; i < n; i++) { if (i == ret.get(j)) { tmp.append('o'); j++; } else { tmp.append('x'); } } pr.println(tmp); } else { pr.println("No"); } pr.close(); sc.close(); } @SuppressWarnings("unused") private static class Scanner { BufferedReader br; Iterator<String> it; Scanner (InputStream in) { br = new BufferedReader(new InputStreamReader(in)); } String next() throws RuntimeException { try { if (it == null || !it.hasNext()) { it = Arrays.asList(br.readLine().split(" ")).iterator(); } return it.next(); } catch (IOException e) { throw new IllegalStateException(); } } int nextInt() throws RuntimeException { return Integer.parseInt(next()); } long nextLong() throws RuntimeException { return Long.parseLong(next()); } float nextFloat() throws RuntimeException { return Float.parseFloat(next()); } double nextDouble() throws RuntimeException { return Double.parseDouble(next()); } void close() { try { br.close(); } catch (IOException e) { // throw new IllegalStateException(); } } } private static class Printer extends PrintWriter { Printer(PrintStream out) { super(out); } } }