結果

問題 No.1021 Children in Classrooms
ユーザー phsplsphspls
提出日時 2020-04-11 13:06:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 1,233 bytes
コンパイル時間 3,498 ms
コンパイル使用メモリ 170,068 KB
実行使用メモリ 5,328 KB
最終ジャッジ日時 2023-10-19 02:33:57
合計ジャッジ時間 3,907 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 3 ms
4,348 KB
testcase_05 AC 3 ms
4,348 KB
testcase_06 AC 3 ms
4,348 KB
testcase_07 AC 3 ms
4,348 KB
testcase_08 AC 3 ms
4,348 KB
testcase_09 AC 77 ms
5,328 KB
testcase_10 AC 77 ms
5,328 KB
testcase_11 AC 77 ms
5,328 KB
testcase_12 AC 76 ms
5,328 KB
testcase_13 AC 77 ms
5,328 KB
testcase_14 AC 76 ms
5,328 KB
testcase_15 AC 58 ms
4,872 KB
testcase_16 AC 59 ms
4,876 KB
testcase_17 AC 61 ms
4,904 KB
testcase_18 AC 82 ms
5,328 KB
testcase_19 AC 8 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define llong long long

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    string s;
    cin >> s;

    int leftpos = 0;
    int rightpos = n-1;
    int left = 0;
    int right = n -1;
    rep(i, s.length()) {
        if(s[i] == 'L') {
            if(leftpos == 0) {
                left = min(left+1, n-1);
            } else {
                leftpos -= 1;
            }
            rightpos = max(0, rightpos-1);
        } else {
            if(rightpos == n-1) {
                right = max(0, right-1);
            } else {
                rightpos += 1;
            }
            leftpos = min(n-1, leftpos+1);
        }
    }

    vector<int> result(n, 0);
    if(leftpos < rightpos) {
        rep(i, left+1) result[leftpos] += a[i];
        for(int i=left+1; i<right; i++) {
            result[leftpos+i-left] += a[i];
        }
        for(int i=right; i<n; i++) {
            result[rightpos] += a[i];
        }
    } else {
        rep(i, n) result[leftpos] += a[i];
    }
    rep(i, n) {
        cout << result[i];
        if(i < n-1) cout << " ";
    }
    cout << "\n";
}
0