結果

問題 No.130 XOR Minimax
ユーザー hama_duhama_du
提出日時 2015-11-24 15:18:26
言語 Go
(1.22.1)
結果
AC  
実行時間 1,246 ms / 5,000 ms
コード長 640 bytes
コンパイル時間 11,133 ms
コンパイル使用メモリ 202,804 KB
実行使用メモリ 8,092 KB
最終ジャッジ日時 2023-10-10 00:11:12
合計ジャッジ時間 24,761 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 485 ms
5,692 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 262 ms
7,920 KB
testcase_05 AC 1,246 ms
8,088 KB
testcase_06 AC 666 ms
7,936 KB
testcase_07 AC 1,100 ms
8,088 KB
testcase_08 AC 1,114 ms
8,092 KB
testcase_09 AC 101 ms
4,352 KB
testcase_10 AC 166 ms
4,348 KB
testcase_11 AC 574 ms
7,940 KB
testcase_12 AC 46 ms
4,352 KB
testcase_13 AC 448 ms
7,940 KB
testcase_14 AC 948 ms
7,944 KB
testcase_15 AC 9 ms
4,348 KB
testcase_16 AC 699 ms
7,944 KB
testcase_17 AC 705 ms
7,944 KB
testcase_18 AC 731 ms
7,944 KB
testcase_19 AC 865 ms
7,948 KB
testcase_20 AC 407 ms
5,684 KB
testcase_21 AC 907 ms
7,944 KB
testcase_22 AC 191 ms
4,352 KB
testcase_23 AC 55 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main
import (
	"fmt"
	"sort"
)

var a []int

func main() {
	var n int
	fmt.Scan(&n)

	a = make([]int, n)
	for i := 0 ; i < n ; i++ {
		fmt.Scan(&a[i])
	}
	sort.Ints(a)

	fmt.Println(solve(1<<30, 0, n))
}

func solve(bit, low, high int) int {
	if bit == 0 {
		return 0
	}

	ln := 0
	hn := 0
	med := -1
	for i := low ; i < high ; i++ {
		if a[i] & bit >= 1 {
			if med == -1 {
				med = i
			}
			hn++
		} else {
			ln++
		}
	}
	if hn == 0 || ln == 0 {
		return solve(bit>>1, low, high)
	}
	left := solve(bit>>1, low, med)
	right := solve(bit>>1, med, high)

	if left < right {
		return left | bit
	} else {
		return right | bit
	}
}
0