結果

問題 No.130 XOR Minimax
ユーザー te-shte-sh
提出日時 2016-09-07 11:23:12
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 198 ms / 5,000 ms
コード長 787 bytes
コンパイル時間 829 ms
コンパイル使用メモリ 110,752 KB
実行使用メモリ 16,976 KB
最終ジャッジ日時 2023-09-02 21:57:41
合計ジャッジ時間 5,280 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
6,692 KB
testcase_01 AC 1 ms
4,372 KB
testcase_02 AC 2 ms
4,368 KB
testcase_03 AC 2 ms
4,372 KB
testcase_04 AC 9 ms
5,652 KB
testcase_05 AC 73 ms
16,976 KB
testcase_06 AC 164 ms
10,684 KB
testcase_07 AC 198 ms
14,872 KB
testcase_08 AC 172 ms
11,384 KB
testcase_09 AC 27 ms
5,892 KB
testcase_10 AC 40 ms
5,888 KB
testcase_11 AC 146 ms
10,092 KB
testcase_12 AC 14 ms
4,368 KB
testcase_13 AC 115 ms
9,716 KB
testcase_14 AC 179 ms
9,772 KB
testcase_15 AC 2 ms
4,368 KB
testcase_16 AC 119 ms
7,676 KB
testcase_17 AC 128 ms
10,168 KB
testcase_18 AC 136 ms
8,612 KB
testcase_19 AC 170 ms
10,000 KB
testcase_20 AC 74 ms
6,240 KB
testcase_21 AC 177 ms
9,096 KB
testcase_22 AC 33 ms
4,856 KB
testcase_23 AC 11 ms
4,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.array, std.container, std.range, std.bitmanip;
import std.numeric, std.math, std.bigint, std.random, core.bitop;
import std.string, std.regex, std.conv, std.stdio, std.typecons;

void main()
{
  auto n = readln.chomp.to!size_t;
  auto ai = readln.split.map!(to!size_t).array;
  writeln(calc(ai));
}

size_t calc(size_t[] ai)
{
  if (ai.length == 1) {
    return 0;
  } else {
    auto maxA = ai.reduce!(max);
    if (maxA == 0) return 0;
    auto b = maxA.bsr;
    auto si = ai.filter!(a => bt(&a, b)).map!(a => a ^ (1 << b)).array;
    auto ri = ai.filter!(a => !bt(&a, b)).array;
    if (si.length == 0) {
      return calc(ri);
    } else if (ri.length == 0) {
      return calc(si);
    } else {
      return min(calc(si), calc(ri)) | (1 << b);
    }
  }
}
0