結果

問題 No.1021 Children in Classrooms
ユーザー oevloevl
提出日時 2020-04-18 17:23:04
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 110 ms / 2,000 ms
コード長 1,284 bytes
コンパイル時間 2,153 ms
コンパイル使用メモリ 198,400 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-14 21:01:43
合計ジャッジ時間 5,086 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 3 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 3 ms
6,944 KB
testcase_07 AC 3 ms
6,944 KB
testcase_08 AC 3 ms
6,940 KB
testcase_09 AC 105 ms
6,940 KB
testcase_10 AC 108 ms
6,944 KB
testcase_11 AC 110 ms
6,944 KB
testcase_12 AC 94 ms
6,940 KB
testcase_13 AC 92 ms
6,944 KB
testcase_14 AC 94 ms
6,944 KB
testcase_15 AC 65 ms
6,944 KB
testcase_16 AC 65 ms
6,940 KB
testcase_17 AC 69 ms
6,940 KB
testcase_18 AC 87 ms
6,940 KB
testcase_19 AC 8 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

enum pos { L, M, R };

int main() {
    int N, M; cin >> N >> M;
    vector<int> A(N);
    for(auto &e : A) cin >> e;
    string S; cin >> S;

    auto side = [&](int x) -> int {
        if(x == 0) return pos::L;
        if(x == N - 1) return pos::R;
        for(auto &c : S) {
            if(c == 'L') x--;
            else x++;
            if(x == 0) return pos::L;
            if(x == N - 1) return pos::R;
        }
        return pos::M;
    };

    int L, R;
    int l = 0, r = N;
    while(r - l > 1) {
        int c = (l + r) / 2;
        if(side(c) == pos::L) l = c;
        else r = c;
    }
    L = l;

    l = -1, r = N - 1;
    while(r - l > 1) {
        int c = (l + r) / 2;
        if(side(c) == pos::R) r = c;
        else l = c;
    }
    R = r;

    auto end = [&](int x) -> int {
        for(auto &c : S) {
            if(c == 'L') x = max(0, x - 1);
            else x = min(N - 1, x + 1);
        }
        return x;
    };

    vector<int> ans(N);
    int a = end(L), b = end(R);
    for(int i = L; i >= 0; --i) ans[a] += A[i];
    for(int i = L + 1; i < R; ++i) ans[++a] = A[i];
    for(int i = R; i < N; ++i) ans[b] += A[i];
    for(int i = 0; i < N; ++i) cout << ans[i] << " ";
    cout << '\n';
    return 0;
}
0