結果

問題 No.1021 Children in Classrooms
コンテスト
ユーザー nebukuro09
提出日時 2020-04-10 21:50:58
言語 D
(dmd 2.112.0)
コンパイル:
dmd -fPIE -m64 -w -wi -O -release -inline -I/opt/dmd/src/druntime/import/ -I/opt/dmd/src/phobos -L-L/opt/dmd/linux/lib64/ -fPIC _filename_
実行:
./Main
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 1,465 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 561 ms
コンパイル使用メモリ 102,060 KB
実行使用メモリ 14,976 KB
最終ジャッジ日時 2026-03-06 12:22:22
合計ジャッジ時間 1,766 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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