結果

問題 No.130 XOR Minimax
ユーザー aru aruaru aru
提出日時 2020-08-14 14:48:09
言語 Go
(1.22.1)
結果
AC  
実行時間 96 ms / 5,000 ms
コード長 1,434 bytes
コンパイル時間 13,420 ms
コンパイル使用メモリ 213,680 KB
実行使用メモリ 8,420 KB
最終ジャッジ日時 2023-10-10 00:29:07
合計ジャッジ時間 14,026 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
8,344 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 32 ms
8,140 KB
testcase_05 AC 37 ms
8,136 KB
testcase_06 AC 46 ms
8,136 KB
testcase_07 AC 50 ms
8,144 KB
testcase_08 AC 96 ms
8,420 KB
testcase_09 AC 13 ms
8,272 KB
testcase_10 AC 18 ms
8,408 KB
testcase_11 AC 52 ms
8,168 KB
testcase_12 AC 7 ms
7,972 KB
testcase_13 AC 41 ms
8,340 KB
testcase_14 AC 95 ms
8,368 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 68 ms
8,356 KB
testcase_17 AC 70 ms
8,360 KB
testcase_18 AC 76 ms
8,368 KB
testcase_19 AC 89 ms
8,368 KB
testcase_20 AC 44 ms
8,412 KB
testcase_21 AC 95 ms
8,372 KB
testcase_22 AC 23 ms
8,112 KB
testcase_23 AC 7 ms
5,644 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func rec(a []int, p int) int {
	if p < 0 {
		return 0
	}
	A := make([]int, 0)
	B := make([]int, 0)
	for _, e := range a {
		if (e>>p)%2 == 0 {
			A = append(A, e)
		} else {
			B = append(B, e)
		}
	}
	ret := 0
	if len(A) == 0 || len(B) == 0 {
		ret = rec(a, p-1)
	} else {
		ret = rec(A, p-1)
		ret = min(ret, rec(B, p-1))
		ret += 1 << p
	}
	return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	N := getInt()
	a := getInts(N)
	out(rec(a, 30))
}
0