結果
問題 | No.9 モンスターのレベル上げ |
ユーザー |
|
提出日時 | 2015-10-25 18:13:24 |
言語 | Go (1.18) |
結果 |
AC
|
実行時間 | 904 ms / 5,000 ms |
コード長 | 1,339 bytes |
コンパイル時間 | 3,065 ms |
使用メモリ | 12,232 KB |
最終ジャッジ日時 | 2023-01-21 15:17:02 |
合計ジャッジ時間 | 12,481 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
テストケース
テストケース表示入力 | 結果 | 実行時間 使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,404 KB |
testcase_01 | AC | 1 ms
5,400 KB |
testcase_02 | AC | 904 ms
10,332 KB |
testcase_03 | AC | 704 ms
10,328 KB |
testcase_04 | AC | 381 ms
10,328 KB |
testcase_05 | AC | 255 ms
12,232 KB |
testcase_06 | AC | 92 ms
11,916 KB |
testcase_07 | AC | 4 ms
6,948 KB |
testcase_08 | AC | 120 ms
10,040 KB |
testcase_09 | AC | 878 ms
10,328 KB |
testcase_10 | AC | 2 ms
6,948 KB |
testcase_11 | AC | 846 ms
10,332 KB |
testcase_12 | AC | 848 ms
12,232 KB |
testcase_13 | AC | 502 ms
10,328 KB |
testcase_14 | AC | 880 ms
10,332 KB |
testcase_15 | AC | 803 ms
10,324 KB |
testcase_16 | AC | 17 ms
6,952 KB |
testcase_17 | AC | 517 ms
10,332 KB |
testcase_18 | AC | 437 ms
10,328 KB |
testcase_19 | AC | 12 ms
7,456 KB |
ソースコード
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 }