結果

問題 No.1021 Children in Classrooms
ユーザー けーむけーむ
提出日時 2020-05-25 22:22:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 56 ms / 2,000 ms
コード長 2,281 bytes
コンパイル時間 1,913 ms
コンパイル使用メモリ 171,088 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-21 03:54:44
合計ジャッジ時間 4,361 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 3 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 3 ms
6,940 KB
testcase_09 AC 53 ms
6,944 KB
testcase_10 AC 56 ms
6,944 KB
testcase_11 AC 53 ms
6,940 KB
testcase_12 AC 51 ms
6,940 KB
testcase_13 AC 51 ms
6,944 KB
testcase_14 AC 53 ms
6,940 KB
testcase_15 AC 33 ms
6,940 KB
testcase_16 AC 32 ms
6,944 KB
testcase_17 AC 34 ms
6,940 KB
testcase_18 AC 44 ms
6,940 KB
testcase_19 AC 5 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n, m;
    cin >> n >> m;
    deque<ll> a(n);
    rep(i, n) cin >> a[i];
    string s;
    cin >> s;
    ll ls = 0, rs = 0;
    rep(i, m) {
        if (s[i] == 'L') {
            if (ls > 0) {
                ls--;
                rs++;
            }
            else {
                if (sz(a) > 1) {
                    rs++;
                    ll tmp = a[0] + a[1];
                    a.pop_front();
                    a.pop_front();
                    a.push_front(tmp);
                }
                else {
                    if (ls > 0) {
                        ls--;
                        rs++;
                    }
                }
            }
        }
        else {
            if (rs > 0) {
                rs--;
                ls++;
            }
            else {
                if (sz(a) > 1) {
                    ls++;
                    ll tmp = a[sz(a) - 1] + a[sz(a) - 2];
                    a.pop_back();
                    a.pop_back();
                    a.push_back(tmp);
                }
                else {
                    if (rs > 0) {
                        rs--;
                        ls++;
                    }
                }
            }
        }
        // printf("ls=%lld, rs=%lld\n", ls, rs);
        // rep(j, sz(a)) printf("%lld%s", a[j], (j == (sz(a) - 1)) ? "\n" : " ");
    }
    ll idx = 0;
    rep(i, n) {
        if (ls > 0) {
            ls--;
            printf("0");
        }
        else if ((sz(a) - 1) >= idx) {
            printf("%lld", a[idx++]);
        }
        else {
            printf("0");
        }
        printf("%s", (i == (n - 1)) ? "\n" : " ");
    }
    return 0;
}
0