結果
| 問題 |
No.130 XOR Minimax
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-09-29 18:01:55 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
AC
|
| 実行時間 | 188 ms / 5,000 ms |
| コード長 | 556 bytes |
| コンパイル時間 | 7,679 ms |
| コンパイル使用メモリ | 171,160 KB |
| 実行使用メモリ | 7,896 KB |
| 最終ジャッジ日時 | 2025-09-29 18:02:14 |
| 合計ジャッジ時間 | 4,657 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 |
ソースコード
module main;
// https://kmjp.hatenablog.jp/entry/2015/01/17/0900 より
// ビット演算
import std;
int f(int d, int[] v)
{
if (v.length <= 1) return 0;
int i, j;
auto w = new int[][](2);
foreach (x; v) {
w[(x >> d) & 1] ~= x ^ (x & (1 << d));
}
if (w[0].empty) return f(d - 1, w[1]);
if (w[1].empty) return f(d - 1, w[0]);
return (1 << d) + min(f(d - 1, w[0]), f(d - 1, w[1]));
}
void main()
{
// 入力
auto N = readln.chomp.to!int;
auto A = readln.split.to!(int[]);
// 答えの計算と出力
writeln(f(29, A.sort.uniq.array));
}