結果
問題 | No.1021 Children in Classrooms |
ユーザー | 小野寺健 |
提出日時 | 2021-12-19 16:05:51 |
言語 | Go (1.22.1) |
結果 |
AC
|
実行時間 | 108 ms / 2,000 ms |
コード長 | 1,199 bytes |
コンパイル時間 | 13,651 ms |
コンパイル使用メモリ | 215,956 KB |
実行使用メモリ | 10,348 KB |
最終ジャッジ日時 | 2023-10-13 18:49:24 |
合計ジャッジ時間 | 16,732 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,352 KB |
testcase_01 | AC | 2 ms
4,352 KB |
testcase_02 | AC | 1 ms
4,348 KB |
testcase_03 | AC | 2 ms
4,356 KB |
testcase_04 | AC | 3 ms
4,352 KB |
testcase_05 | AC | 2 ms
4,352 KB |
testcase_06 | AC | 2 ms
4,348 KB |
testcase_07 | AC | 2 ms
4,348 KB |
testcase_08 | AC | 3 ms
4,352 KB |
testcase_09 | AC | 107 ms
10,348 KB |
testcase_10 | AC | 106 ms
10,348 KB |
testcase_11 | AC | 108 ms
10,348 KB |
testcase_12 | AC | 104 ms
10,216 KB |
testcase_13 | AC | 106 ms
10,272 KB |
testcase_14 | AC | 106 ms
10,288 KB |
testcase_15 | AC | 71 ms
7,876 KB |
testcase_16 | AC | 71 ms
7,880 KB |
testcase_17 | AC | 76 ms
7,884 KB |
testcase_18 | AC | 84 ms
7,900 KB |
testcase_19 | AC | 7 ms
4,352 KB |
ソースコード
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 { var builder strings.Builder for i := 0; i < len(a); i++ { builder.WriteString(strconv.Itoa(a[i]) + " ") } return builder.String() } 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) }