結果

問題 No.1021 Children in Classrooms
ユーザー hiroaki0615hiroaki0615
提出日時 2020-04-10 21:51:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 1,406 bytes
コンパイル時間 659 ms
コンパイル使用メモリ 69,792 KB
実行使用メモリ 5,260 KB
最終ジャッジ日時 2023-10-14 00:20:34
合計ジャッジ時間 2,521 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,372 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 AC 2 ms
4,372 KB
testcase_03 AC 2 ms
4,372 KB
testcase_04 AC 2 ms
4,372 KB
testcase_05 AC 1 ms
4,368 KB
testcase_06 AC 2 ms
4,372 KB
testcase_07 AC 2 ms
4,372 KB
testcase_08 AC 2 ms
4,368 KB
testcase_09 AC 31 ms
4,992 KB
testcase_10 AC 31 ms
5,012 KB
testcase_11 AC 31 ms
4,984 KB
testcase_12 AC 31 ms
5,060 KB
testcase_13 AC 30 ms
5,228 KB
testcase_14 AC 31 ms
4,948 KB
testcase_15 AC 23 ms
4,740 KB
testcase_16 AC 23 ms
4,780 KB
testcase_17 AC 24 ms
4,704 KB
testcase_18 AC 31 ms
5,260 KB
testcase_19 AC 3 ms
4,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    vector<ll> A(N);
    for (auto& a : A) {
        cin >> a;
    }
    string S;
    cin >> S;
    int l = 0, r = N - 1;
    int l_cnt = 0, r_cnt = 0;
    rep(i, 0, M) {
        if (S[i] == 'L' && r_cnt < N - 1) {
            ++r_cnt;
            if (l_cnt) {
                --l_cnt;
            }
            else {
                A[l + 1] += A[l];
                ++l;
            }
        }
        else if (S[i] == 'R' && l_cnt < N - 1) {
            ++l_cnt;
            if (r_cnt) {
                --r_cnt;
            }
            else {
                A[r - 1] += A[r];
                --r;
            }
        }
    }
    rep(i, 0, l_cnt) {
        cout << 0 << ' ';
    }
    rep(i, l, r + 1) {
        cout << A[i] << ' ';
    }
    rep(i, 0, r_cnt) {
        cout << 0 << ' ';
    }
    cout << endl;
    return 0;
}
0