結果
問題 | No.130 XOR Minimax |
ユーザー |
|
提出日時 | 2016-09-07 11:23:12 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 167 ms / 5,000 ms |
コード長 | 787 bytes |
コンパイル時間 | 828 ms |
コンパイル使用メモリ | 121,600 KB |
実行使用メモリ | 14,740 KB |
最終ジャッジ日時 | 2024-06-12 04:12:05 |
合計ジャッジ時間 | 3,922 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
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);}}}