結果

問題 No.205 マージして辞書順最小
ユーザー yukirinyukirin
提出日時 2016-03-31 15:46:51
言語 Go
(1.22.1)
結果
WA  
実行時間 -
コード長 962 bytes
コンパイル時間 12,505 ms
コンパイル使用メモリ 225,540 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-19 07:11:53
合計ジャッジ時間 11,862 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 1 ms
5,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 WA -
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	n, b := nextInt(), make([]byte, 0, 2500)
	q := make(priorityQ, 0, 50)

	heap.Init(&q)
	for i := 0; i < n; i++ {
		heap.Push(&q, nextLine())
	}

	for q.Len() > 0 {
		s := heap.Pop(&q).(string)
		b = append(b, s[0])

		if len(s) == 1 {
			continue
		}

		heap.Push(&q, s[1:])
	}

	fmt.Println(string(b))
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextLine())
	return i
}

type priorityQ []string

func (h priorityQ) Len() int {
	return len(h)
}

func (h priorityQ) Less(i, j int) bool {
	return h[i] < h[j]
}

func (h priorityQ) Swap(i, j int) {
	h[i], h[j] = h[j], h[i]
}

func (h *priorityQ) Push(x interface{}) {
	*h = append(*h, x.(string))
}

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