結果

問題 No.1021 Children in Classrooms
ユーザー aru aruaru aru
提出日時 2020-10-02 22:24:14
言語 Go
(1.22.1)
結果
AC  
実行時間 420 ms / 2,000 ms
コード長 1,630 bytes
コンパイル時間 15,396 ms
コンパイル使用メモリ 215,876 KB
実行使用メモリ 33,688 KB
最終ジャッジ日時 2023-09-24 21:24:03
合計ジャッジ時間 21,429 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 4 ms
4,376 KB
testcase_04 AC 4 ms
4,380 KB
testcase_05 AC 4 ms
4,376 KB
testcase_06 AC 4 ms
4,380 KB
testcase_07 AC 5 ms
4,380 KB
testcase_08 AC 5 ms
4,380 KB
testcase_09 AC 417 ms
31,596 KB
testcase_10 AC 419 ms
31,592 KB
testcase_11 AC 420 ms
31,632 KB
testcase_12 AC 419 ms
33,688 KB
testcase_13 AC 417 ms
31,616 KB
testcase_14 AC 420 ms
33,688 KB
testcase_15 AC 329 ms
27,392 KB
testcase_16 AC 332 ms
27,388 KB
testcase_17 AC 343 ms
27,400 KB
testcase_18 AC 419 ms
29,524 KB
testcase_19 AC 40 ms
8,188 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"bufio"
	"container/list"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

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

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)
	N, _ := getInt(), getInt()
	a := getInts(N)
	S := getString()

	l := list.New()
	for i := 0; i < N; i++ {
		l.PushBack(a[i])
	}
	for _, e := range S {
		if e == 'L' {
			e := l.Front()
			x := e.Value.(int)
			l.Remove(e)
			e = l.Front()
			x += e.Value.(int)
			l.Remove(e)
			l.PushFront(x)
			l.PushBack(0)
		} else {
			e := l.Back()
			x := e.Value.(int)
			l.Remove(e)
			e = l.Back()
			x += e.Value.(int)
			l.Remove(e)
			l.PushBack(x)
			l.PushFront(0)
		}
	}

	for e := l.Front(); e != nil; e = e.Next() {
		fmt.Print(e.Value, " ")
	}
	out()
}
0