結果

問題 No.130 XOR Minimax
ユーザー te-shte-sh
提出日時 2017-01-30 22:56:07
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 948 ms / 5,000 ms
コード長 866 bytes
コンパイル時間 963 ms
コンパイル使用メモリ 91,248 KB
実行使用メモリ 20,364 KB
最終ジャッジ日時 2023-09-03 01:06:12
合計ジャッジ時間 9,215 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 393 ms
6,408 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 12 ms
5,880 KB
testcase_05 AC 123 ms
20,364 KB
testcase_06 AC 141 ms
7,976 KB
testcase_07 AC 190 ms
14,608 KB
testcase_08 AC 948 ms
8,412 KB
testcase_09 AC 39 ms
4,380 KB
testcase_10 AC 56 ms
4,796 KB
testcase_11 AC 144 ms
7,468 KB
testcase_12 AC 23 ms
4,384 KB
testcase_13 AC 120 ms
6,640 KB
testcase_14 AC 791 ms
7,816 KB
testcase_15 AC 10 ms
4,376 KB
testcase_16 AC 546 ms
6,384 KB
testcase_17 AC 568 ms
7,324 KB
testcase_18 AC 608 ms
7,372 KB
testcase_19 AC 740 ms
7,704 KB
testcase_20 AC 352 ms
6,552 KB
testcase_21 AC 787 ms
7,500 KB
testcase_22 AC 170 ms
4,548 KB
testcase_23 AC 52 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[]);

  int calc(size_t i, int[] ai) {
    if (ai.empty) return int.max;
    auto bi = ai.filter!(a => a.bitTest(i)).map!(a => a.bitReset(i)).array;
    auto ci = ai.filter!(a => !a.bitTest(i)).array;
    if (i == 0) return bi.empty || ci.empty ? 0 : 1;
    auto b = calc(i - 1, bi);
    if (!ci.empty) b = b.bitSet(i);
    auto c = calc(i - 1, ci);
    if (!bi.empty) c = c.bitSet(i);
    return min(b, c);
  }

  writeln(calc(ai.fold!max.bsr, ai));
}

bool bitTest(T)(T n, size_t i) { return (n & (1 << i)) != 0; }
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