結果

問題 No.9 モンスターのレベル上げ
ユーザー warashiwarashi
提出日時 2015-10-25 18:13:24
言語 Go
(1.22.1)
結果
AC  
実行時間 911 ms / 5,000 ms
コード長 1,339 bytes
コンパイル時間 13,104 ms
コンパイル使用メモリ 214,104 KB
実行使用メモリ 8,260 KB
最終ジャッジ日時 2023-09-06 04:24:47
合計ジャッジ時間 22,647 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 911 ms
8,256 KB
testcase_03 AC 706 ms
8,252 KB
testcase_04 AC 382 ms
8,256 KB
testcase_05 AC 254 ms
8,252 KB
testcase_06 AC 91 ms
7,976 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 120 ms
8,072 KB
testcase_09 AC 883 ms
8,256 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 850 ms
8,252 KB
testcase_12 AC 857 ms
8,260 KB
testcase_13 AC 508 ms
8,260 KB
testcase_14 AC 888 ms
8,252 KB
testcase_15 AC 810 ms
8,260 KB
testcase_16 AC 17 ms
4,380 KB
testcase_17 AC 518 ms
8,256 KB
testcase_18 AC 439 ms
8,256 KB
testcase_19 AC 11 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"container/heap"
	"fmt"
)

const offset = 16384

// 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