結果
問題 | No.130 XOR Minimax |
ユーザー | Grenache |
提出日時 | 2016-06-15 19:24:50 |
言語 | Java21 (openjdk 21) |
結果 |
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 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 928 ms
79,216 KB |
testcase_01 | AC | 57 ms
50,656 KB |
testcase_02 | AC | 57 ms
50,316 KB |
testcase_03 | AC | 60 ms
50,544 KB |
testcase_04 | AC | 183 ms
58,600 KB |
testcase_05 | AC | 256 ms
62,564 KB |
testcase_06 | AC | 553 ms
77,168 KB |
testcase_07 | AC | 680 ms
81,836 KB |
testcase_08 | AC | 1,517 ms
89,300 KB |
testcase_09 | AC | 266 ms
56,808 KB |
testcase_10 | AC | 311 ms
58,932 KB |
testcase_11 | AC | 621 ms
71,004 KB |
testcase_12 | AC | 199 ms
56,420 KB |
testcase_13 | AC | 489 ms
63,332 KB |
testcase_14 | AC | 1,572 ms
87,320 KB |
testcase_15 | AC | 133 ms
55,724 KB |
testcase_16 | AC | 1,163 ms
81,324 KB |
testcase_17 | AC | 1,184 ms
81,220 KB |
testcase_18 | AC | 1,228 ms
81,320 KB |
testcase_19 | AC | 1,332 ms
86,744 KB |
testcase_20 | AC | 870 ms
79,416 KB |
testcase_21 | AC | 1,425 ms
87,152 KB |
testcase_22 | AC | 525 ms
68,888 KB |
testcase_23 | AC | 267 ms
56,596 KB |
ソースコード
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); } } }