結果

問題 No.1021 Children in Classrooms
ユーザー TAISA_
提出日時 2020-04-10 21:31:29
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 1,644 bytes
コンパイル時間 2,658 ms
コンパイル使用メモリ 198,716 KB
最終ジャッジ日時 2025-01-09 15:59:29
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
#define pb push_back
#define eb emplace_back
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using V = vector<int>;
using VL = vector<ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll MOD = 1e9 + 7;
constexpr int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
template <class T>
void chmin(T &a, T b) { a = min(a, b); }
template <class T>
void chmax(T &a, T b) { a = max(a, b); }
void ok() { cerr << "ok" << endl; }
int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n, m;
    cin >> n >> m;
    VL a(n);
    deque<ll> q;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        q.pb(a[i]);
    }
    int l = 0, r = n - 1;
    string s;
    cin >> s;
    for (int i = 0; i < m; i++) {
        if (s[i] == 'L') {
            if (q.size() > 1 && l == 0) {
                ll s = q.front();
                q.pop_front();
                s += q.front();
                q.pop_front();
                q.push_front(s);
            }
            r = max(0, r - 1);
            l = max(0, l - 1);
        } else {
            if (q.size() > 1 && r == n - 1) {
                ll s = q.back();
                q.pop_back();
                s += q.back();
                q.pop_back();
                q.push_back(s);
            }
            l = min(n - 1, l + 1);
            r = min(n - 1, r + 1);
        }
    }
    for (int i = 0; i < n; i++) {
        if (l <= i && i <= r) {
            cout << q.front();
            q.pop_front();
        } else {
            cout << 0;
        }
        cout << (i + 1 == n ? '\n' : ' ');
    }
}
0