結果

問題 No.9 モンスターのレベル上げ
ユーザー warashi
提出日時 2015-10-25 18:14:50
言語 Go
(1.23.4)
結果
AC  
実行時間 905 ms / 5,000 ms
コード長 1,339 bytes
コンパイル時間 10,840 ms
コンパイル使用メモリ 225,064 KB
実行使用メモリ 8,108 KB
最終ジャッジ日時 2024-06-23 23:16:21
合計ジャッジ時間 20,010 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"container/heap"
	"fmt"
)

const offset = 10000

// An IntHeap is a min-heap of ints.
type IntHeap []int

func (h IntHeap) Len() int           { return len(h) }
func (h IntHeap) Less(i, j int) bool { return h[i] < h[j] }
func (h IntHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }

func (h *IntHeap) Push(x interface{}) {
	// Push and Pop use pointer receivers because they modify the slice's length,
	// not just its contents.
	*h = append(*h, x.(int))
}

func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

func main() {
	var N, tmp int
	fmt.Scan(&N)
	A := make(IntHeap, N)
	B := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&tmp)
		A[i] = tmp * offset
	}
	heap.Init(&A)

	for i := 0; i < N; i++ {
		fmt.Scan(&B[i])
	}

	min := N + 1
	for i := 0; i < N; i++ {
		tmp = calc(i, A, B)
		if tmp < min {
			min = tmp
		}
	}
	fmt.Println(min)
}

func calc(start int, A IntHeap, B []int) int {
	N := len(B)
	h := make(IntHeap, len(A))
	copy(h, A)

	for i := 0; i < N; i++ {
		j := start + i
		if j >= len(B) {
			j -= len(B)
		}
		l := heap.Pop(&h)
		nl := l.(int) + ((B[j] / 2) * offset) + 1
		heap.Push(&h, nl)
	}

	var tmp, count int
	for h.Len() > 0 {
		tmp = heap.Pop(&h).(int) % offset
		if tmp > count {
			count = tmp
		}
	}
	return count
}
0