結果

問題 No.1021 Children in Classrooms
ユーザー merom686
提出日時 2020-04-10 21:46:08
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 869 bytes
コンパイル時間 769 ms
コンパイル使用メモリ 76,264 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-15 19:50:36
合計ジャッジ時間 2,353 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    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 l = 0;
    for (int j = 0; j < m; j++) {
        if (s[j] == 'L') {
            if (l >= 0 && l + 1 < n) a[l + 1] += a[l], a[l] = 0;
            if (l + 1 < n) l++;
        } else {
            int r = l + n - 1;
            if (r < n && r - 1 >= 0) a[r - 1] += a[r], a[r] = 0;
            if (r - 1 >= 0) l--;
        }
    }

    for (int i = 0; i < n; i++) {
        int k = l + i;
        cout << ((0 <= k && k < n) ? a[k] : 0) << " \n"[i == n - 1];
    }

    return 0;
}
0