結果

問題 No.1021 Children in Classrooms
ユーザー nebukuro09nebukuro09
提出日時 2020-04-10 21:50:58
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 73 ms / 2,000 ms
コード長 1,465 bytes
コンパイル時間 1,714 ms
コンパイル使用メモリ 110,136 KB
実行使用メモリ 14,244 KB
最終ジャッジ日時 2023-09-04 07:14:08
合計ジャッジ時間 3,269 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 73 ms
13,036 KB
testcase_10 AC 73 ms
12,544 KB
testcase_11 AC 73 ms
12,308 KB
testcase_12 AC 72 ms
12,040 KB
testcase_13 AC 71 ms
12,584 KB
testcase_14 AC 71 ms
12,312 KB
testcase_15 AC 51 ms
10,400 KB
testcase_16 AC 52 ms
10,732 KB
testcase_17 AC 54 ms
10,524 KB
testcase_18 AC 73 ms
14,244 KB
testcase_19 AC 4 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdlib;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    auto A = readln.split.map!(to!long).array;
    auto S = readln.chomp;

    int left = 0;
    int right = N - 1;

    int left_end = 0;
    int right_end = N - 1;

    int diff = 0;

    foreach (i; 0..M) {
        auto c = S[i];
        if (c == 'L') {
            if (left_end == 0) {
                left = min(N - 1, left + 1);
                right_end = max(0, right_end - 1);
            } else {
                left_end = max(0, left_end - 1);
                right_end = max(0, right_end - 1);
            }
            diff -= 1;
        } else {
            if (right_end == N - 1) {
                right = max(0, right - 1);
                left_end = min(N - 1, left_end + 1);
            } else {
                left_end = min(N - 1, left_end + 1);
                right_end = min(N - 1, right_end + 1);
            }
            diff += 1;
        }
    }

    auto ans = new long[](N);

    foreach (i; 0..N) {
        if (i <= left) {
            ans[left_end] += A[i];
        } else if (i >= right) {
            ans[right_end] += A[i];
        } else {
            ans[i + diff] += A[i];
        }
    }

    ans.map!(to!string).join(" ").writeln;
}
0