結果

問題 No.1021 Children in Classrooms
ユーザー Moon0603Moon0603
提出日時 2020-04-11 18:19:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 1,420 bytes
コンパイル時間 2,414 ms
コンパイル使用メモリ 204,020 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2023-10-19 09:41:39
合計ジャッジ時間 4,626 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 3 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 3 ms
4,348 KB
testcase_09 AC 37 ms
5,232 KB
testcase_10 AC 38 ms
5,236 KB
testcase_11 AC 38 ms
5,228 KB
testcase_12 AC 35 ms
5,232 KB
testcase_13 AC 36 ms
5,224 KB
testcase_14 AC 36 ms
5,228 KB
testcase_15 AC 27 ms
4,816 KB
testcase_16 AC 27 ms
4,836 KB
testcase_17 AC 28 ms
4,816 KB
testcase_18 AC 36 ms
5,376 KB
testcase_19 AC 5 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, m;
    cin >> n >> m;

    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }

    string s;
    cin >> s;

    int mn, mx = mn = 0;
    int cur = 0;

    for (int i = 0; i < m; ++i) {
        if (s[i] == 'L') {
            --cur;
        }
        else {
            ++cur;
        }
        mn = min(cur, mn);
        mx = max(cur, mx);
    }

    for (int i = 0; i < n - 1; ++i) {
        if (i + mn < 0) {
            a[i + 1] += a[i];
            a[i] = 0;
        }
    }

    for (int i = n - 1; i > 0; --i) {
        if (i + mx >= n) {
            a[i - 1] += a[i];
            a[i] = 0;
        }
    }

    vector<int> ans(n);

    for (int i = 1; i < n - 1; ++i) {
        if (a[i] > 0) {
            ans[i + cur] += a[i];
        }
    }

    int fi = 0, se = n - 1;

    for (int i = 0; i < m; ++i) {
        if (s[i] == 'L') {
            --fi;
            --se;
        }
        else {
            ++fi;
            ++se;
        }
        fi = max(fi, 0);
        se = max(se, 0);
        fi = min(fi, n - 1);
        se = min(se, n - 1);
    }

    ans[fi] += a[0];
    ans[se] += a[n - 1];

    for (int i = 0; i < n; ++i) {
        if (i > 0) {
            cout << " ";
        }
        cout << ans[i];
    }
    cout << '\n';

    return 0;
}
0