結果
問題 |
No.205 マージして辞書順最小
|
ユーザー |
|
提出日時 | 2016-03-31 15:46:51 |
言語 | Go (1.23.4) |
結果 |
WA
|
実行時間 | - |
コード長 | 962 bytes |
コンパイル時間 | 11,678 ms |
コンパイル使用メモリ | 219,744 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-10-10 23:51:03 |
合計ジャッジ時間 | 12,090 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 WA * 1 |
other | AC * 7 WA * 8 |
ソースコード
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 }