結果

問題 No.893 お客様を誘導せよ
ユーザー neko_the_shadow
提出日時 2019-12-13 15:58:26
言語 Go
(1.23.4)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 875 bytes
コンパイル時間 15,539 ms
コンパイル使用メモリ 237,544 KB
実行使用メモリ 10,296 KB
最終ジャッジ日時 2024-06-27 04:22:37
合計ジャッジ時間 15,849 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

func main() {
	n := readInt()
	a := make([][]int, 0)
	sum := 0
	for i := 0; i < n; i++ {
		p := readInt()
		a = append(a, []int{})
		sum += p
		for j := 0; j < p; j++ {
			a[i] = append(a[i], readInt())
		}
	}

	b := []int{}
	x := 0
	for i := 0; i < sum; i++ {
		for len(a[x]) == 0 {
			x = (x + 1) % n
		}
		b = append(b, a[x][0])
		a[x] = a[x][1:]
		x = (x + 1) % n
	}

	c := []string{}
	for _, v := range b {
		c = append(c, strconv.Itoa(v))
	}
	fmt.Println(strings.Join(c, " "))
}

var stdin *bufio.Scanner

func read() string {
	if stdin == nil {
		stdin = bufio.NewScanner(os.Stdin)
		stdin.Split(bufio.ScanWords)
		stdin.Buffer(make([]byte, bufio.MaxScanTokenSize), int(math.MaxInt32))
	}
	stdin.Scan()
	return stdin.Text()
}

func readInt() int {
	n, _ := strconv.Atoi(read())
	return n
}
0