CC's

Back

Today, as a friendship gift, Bakry gave Badawy n integers a1,a2,…,an and challenged him to choose an integer X such that the value max1≤i≤n(ai⊕X) is minimum possible, where ⊕ denotes the bitwise XOR operation.

As always, Badawy is too lazy, so you decided to help him and find the minimum possible value of max1≤i≤n(ai⊕X).

分析#

将输入按照二进制位从高位开始建树,就能看出来,一旦确定了高位ii填1还是0后,只会有一棵子树影响答案.另一棵子树的所有数字都因为ii位上的异或结果为0而定小于另一个子树.

树不用真的建出来,这样就可以做了.

代码#

CF1285D Dr.Evil Underscores
https://astro-pure.js.org/blog/cf1285d-dr-evil-underscores
Author Cheng Chen
Published at 2020年1月13日
Comment seems to stuck. Try to refresh?✨