結果
| 問題 |
No.1021 Children in Classrooms
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-12-19 15:55:31 |
| 言語 | Go (1.23.4) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,148 bytes |
| コンパイル時間 | 15,102 ms |
| コンパイル使用メモリ | 220,536 KB |
| 実行使用メモリ | 15,252 KB |
| 最終ジャッジ日時 | 2024-09-15 14:35:01 |
| 合計ジャッジ時間 | 17,970 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 6 TLE * 1 -- * 10 |
ソースコード
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)
}