結果
問題 | No.130 XOR Minimax |
ユーザー |
|
提出日時 | 2016-06-15 19:24:50 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 1,572 ms / 5,000 ms |
コード長 | 2,328 bytes |
コンパイル時間 | 4,361 ms |
コンパイル使用メモリ | 80,352 KB |
実行使用メモリ | 89,300 KB |
最終ジャッジ日時 | 2024-09-12 22:41:55 |
合計ジャッジ時間 | 21,928 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
import java.io.*;import java.util.*;public class Main_yukicoder130_1 {public static void main(String[] args) {Scanner sc = new Scanner(System.in);Printer pr = new Printer(System.out);int n = sc.nextInt();SortedSet<Integer> a = new TreeSet<>();for (int i = 0; i < n; i++) {a.add(sc.nextInt());}pr.println(rec(0, 0, 0, a));pr.close();sc.close();}private static int rec(int mask, int bit, int max, SortedSet<Integer> a) {if (mask == 0x7fffffff) {return max;}int nmask = mask >>> 1 | 0x40000000;int nbit = ((~mask & 0x7fffffff) + 1) >>> 1;int to1 = (~nmask & 0x7fffffff | bit) + 1;int to2 = (~nmask & 0x7fffffff | bit | nbit) + 1;if (to1 < 0) {to1 = Integer.MAX_VALUE;}if (to2 < 0) {to2 = Integer.MAX_VALUE;}SortedSet<Integer> a1 = a.subSet(bit, to1);SortedSet<Integer> a2 = a.subSet(bit | nbit, to2);if (a1.size() == 0 && a2.size() == 0) {return Integer.MAX_VALUE;} else if (a2.size() == 0) {return rec(nmask, bit, max, a);} else if (a1.size() == 0) {return rec(nmask, bit | nbit, max, a);} else {return Math.min(rec(nmask, bit, max | nbit, a), rec(nmask, bit | nbit, max | nbit, a));}}@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);}}}