結果

問題 No.130 XOR Minimax
ユーザー te-shte-sh
提出日時 2017-01-31 11:37:42
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 192 ms / 5,000 ms
コード長 791 bytes
コンパイル時間 723 ms
コンパイル使用メモリ 95,284 KB
実行使用メモリ 9,056 KB
最終ジャッジ日時 2023-09-03 01:07:11
合計ジャッジ時間 3,987 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 102 ms
6,120 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 11 ms
5,316 KB
testcase_05 AC 40 ms
9,056 KB
testcase_06 AC 66 ms
7,608 KB
testcase_07 AC 83 ms
9,008 KB
testcase_08 AC 175 ms
7,444 KB
testcase_09 AC 17 ms
4,384 KB
testcase_10 AC 24 ms
6,168 KB
testcase_11 AC 65 ms
7,448 KB
testcase_12 AC 10 ms
4,376 KB
testcase_13 AC 54 ms
6,540 KB
testcase_14 AC 192 ms
6,772 KB
testcase_15 AC 4 ms
4,376 KB
testcase_16 AC 135 ms
6,048 KB
testcase_17 AC 142 ms
6,832 KB
testcase_18 AC 150 ms
6,224 KB
testcase_19 AC 179 ms
6,976 KB
testcase_20 AC 90 ms
5,044 KB
testcase_21 AC 190 ms
7,020 KB
testcase_22 AC 44 ms
4,380 KB
testcase_23 AC 15 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.conv, std.range, std.stdio, std.string;
import core.bitop;    // bit operation

void main()
{
  auto n = readln.chomp.to!size_t;
  auto ai = readln.split.to!(int[]);
  ai.sort();

  int calc(int[] ai) {
    if (ai.empty) return int.max;
    if (ai.back == 0) return 0;
    auto i = ai.back.bsr, bi = ai.assumeSorted;
    auto ci = bi.lowerBound(1 << i).array;
    auto di = bi.upperBound((1 << i) - 1).map!(a => a.bitReset(i)).array;
    auto c = calc(ci);
    if (!di.empty) c = c.bitSet(i);
    auto d = calc(di);
    if (!ci.empty) d = d.bitSet(i);
    return min(c, d);
  }

  writeln(calc(ai));
}

T bitSet(T)(T n, size_t i) { return n | (1 << i); }
T bitReset(T)(T n, size_t i) { return n & ~(1 << i); }
int bsr(T)(T n) { return core.bitop.bsr(n.to!ulong); }
0