結果

問題 No.130 XOR Minimax
ユーザー ccppjsrbccppjsrb
提出日時 2020-10-01 20:50:26
言語 Go
(1.22.1)
結果
AC  
実行時間 39 ms / 5,000 ms
コード長 1,893 bytes
コンパイル時間 11,390 ms
コンパイル使用メモリ 213,872 KB
実行使用メモリ 5,484 KB
最終ジャッジ日時 2023-10-10 00:29:47
合計ジャッジ時間 12,976 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
4,352 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 6 ms
5,484 KB
testcase_05 AC 12 ms
5,484 KB
testcase_06 AC 9 ms
5,480 KB
testcase_07 AC 13 ms
5,480 KB
testcase_08 AC 27 ms
5,480 KB
testcase_09 AC 5 ms
4,380 KB
testcase_10 AC 8 ms
4,356 KB
testcase_11 AC 24 ms
5,480 KB
testcase_12 AC 3 ms
4,348 KB
testcase_13 AC 19 ms
4,372 KB
testcase_14 AC 39 ms
5,480 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 28 ms
4,352 KB
testcase_17 AC 29 ms
4,352 KB
testcase_18 AC 31 ms
4,348 KB
testcase_19 AC 37 ms
5,480 KB
testcase_20 AC 19 ms
4,348 KB
testcase_21 AC 39 ms
5,480 KB
testcase_22 AC 9 ms
4,348 KB
testcase_23 AC 3 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

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

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	aa := make([]int, n)
	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
	}
	sort.Ints(aa)
	var dfs func(int, int, int) int
	dfs = func(i, l, r int) int {
		if l == r {
			return math.MaxInt32
		}
		ll := l - 1
		rr := r
		for ll+1 < rr {
			m := (ll + rr) >> 1
			if aa[m]>>uint(i)&1 == 1 {
				rr = m
				continue
			}
			ll = m
		}
		if r == rr || l-1 == ll {
			if i == 0 {
				return 0
			}
			return dfs(i-1, l, r)
		}
		if i == 0 {
			return 1
		}
		return min(1<<uint(i)|dfs(i-1, l, rr), 1<<uint(i)|dfs(i-1, rr, r))
	}
	fmt.Fprintln(writer, dfs(30, 0, n))
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
0