結果
| 問題 |
No.120 傾向と対策:門松列(その1)
|
| コンテスト | |
| ユーザー |
fmhr
|
| 提出日時 | 2015-05-29 13:21:33 |
| 言語 | Go1.4 (1.4.2) |
| 結果 |
AC
|
| 実行時間 | 93 ms / 5,000 ms |
| コード長 | 1,433 bytes |
| コンパイル時間 | 279 ms |
| コンパイル使用メモリ | 34,744 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-25 00:21:30 |
| 合計ジャッジ時間 | 1,145 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 4 |
ソースコード
package main
import (
"bufio"
"container/heap"
"fmt"
"os"
"strconv"
)
///heap/////////////////////////////////
// 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
}
////nextInt////////////////////////////
var s = bufio.NewScanner(os.Stdin)
func next() string {
s.Split(bufio.ScanWords)
s.Scan()
return s.Text()
}
func nextInt() int {
i, e := strconv.Atoi(next())
if e != nil {
panic(e)
}
return int(i)
}
/////solve///////////////////////////////////////
func solve() {
N := nextInt()
m := make(map[int]int)
for i := 0; i < N; i++ {
z := nextInt()
m[z]++
}
h := &IntHeap{}
for _, v := range m {
heap.Push(h, v)
}
var ans int
for h.Len() >= 3 {
a := make([]int, 3)
ans += 1
for i := 0; i < 3; i++ {
a[i] = heap.Pop(h).(int) - 1
}
//fmt.Println(a)
for i := 0; i < 3; i++ {
if a[i] > 0 {
heap.Push(h, a[i])
}
}
}
fmt.Println(ans)
}
func main() {
T := nextInt()
for i := 0; i < T; i++ {
solve()
}
}
fmhr