結果

問題 No.1021 Children in Classrooms
ユーザー 小野寺健小野寺健
提出日時 2021-12-19 15:55:31
言語 Go
(1.22.1)
結果
TLE  
実行時間 -
コード長 1,148 bytes
コンパイル時間 13,476 ms
コンパイル使用メモリ 205,024 KB
実行使用メモリ 14,876 KB
最終ジャッジ日時 2023-10-13 18:48:31
合計ジャッジ時間 19,028 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

package main

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

func Sum (a []int) string {
	sum := 0
	for _, v := range a {
		sum += v
	}
	return strconv.Itoa(sum)
}

func Join (a []int) string {
	s := ""
	for i := 0; i < len(a); i++ {
		s += strconv.Itoa(a[i]) + " "
	}
	return s
}

func main() {
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()
	var N, M int
	fmt.Fscan(r, &N, &M)
	a := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Fscan(r, &a[i])
	}
	var S string
	fmt.Fscan(r, &S)
	lindex := 0
	rindex := N - 1
	ln, rn := 1, 1
	for i := 0; i < len(S); i++ {
		if S[i] == 'L' {
			if lindex == 0 && ln < N { ln++ }
			if lindex > 0 { lindex-- }
			if rindex > 0 { rindex-- }
		} else {
			if rindex == N - 1 && rn < N { rn++ }
			if rindex < N - 1 { rindex++ }
			if lindex < N - 1 { lindex++ }	
		}
	}
	ans := ""
	ans += strings.Repeat("0 ", lindex)
	if rindex == lindex {
		ans += Sum(a)
	} else if ln + rn == N {
		ans += Sum(a[0:ln]) + " " + Sum(a[N-rn:N])
	} else {
		ans += Sum(a[0:ln]) + " " + Join(a[ln:N-rn]) + Sum(a[N-rn:N]) 
	}
	ans += strings.Repeat(" 0", N-1-rindex)
	fmt.Fprintln(w, ans)
}
0