結果

問題 No.130 XOR Minimax
ユーザー te-shte-sh
提出日時 2017-01-30 22:36:48
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 864 bytes
コンパイル時間 2,426 ms
コンパイル使用メモリ 91,432 KB
実行使用メモリ 19,196 KB
最終ジャッジ日時 2023-09-03 01:05:22
合計ジャッジ時間 9,949 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 376 ms
5,832 KB
testcase_01 WA -
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 10 ms
5,960 KB
testcase_05 AC 119 ms
19,196 KB
testcase_06 AC 112 ms
8,060 KB
testcase_07 WA -
testcase_08 AC 906 ms
8,288 KB
testcase_09 AC 34 ms
4,384 KB
testcase_10 AC 47 ms
5,952 KB
testcase_11 AC 121 ms
7,448 KB
testcase_12 AC 20 ms
4,380 KB
testcase_13 AC 100 ms
6,504 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 717 ms
7,752 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 51 ms
4,384 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;
    if (i == 0) return ai.fold!max;
    auto bi = ai.filter!(a => a.bitTest(i)).map!(a => a.bitReset(i)).array;
    auto ci = ai.filter!(a => !a.bitTest(i)).array;
    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.to!T << i)) != 0; }
T bitSet(T)(T n, size_t i) { return n | (1.to!T << i); }
T bitReset(T)(T n, size_t i) { return n & ~(1.to!T << i); }
int bsr(T)(T n) { return core.bitop.bsr(n.to!ulong); }
0