結果

問題 No.1021 Children in Classrooms
ユーザー ei13337ei13337
提出日時 2020-04-10 22:35:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 2,004 bytes
コンパイル時間 1,012 ms
コンパイル使用メモリ 112,804 KB
実行使用メモリ 8,128 KB
最終ジャッジ日時 2023-10-14 01:23:47
合計ジャッジ時間 2,906 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 2 ms
4,352 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 36 ms
6,544 KB
testcase_10 AC 35 ms
6,560 KB
testcase_11 AC 35 ms
6,640 KB
testcase_12 AC 35 ms
6,680 KB
testcase_13 AC 35 ms
6,612 KB
testcase_14 AC 35 ms
6,616 KB
testcase_15 AC 28 ms
7,044 KB
testcase_16 AC 28 ms
7,256 KB
testcase_17 AC 29 ms
7,160 KB
testcase_18 AC 37 ms
8,128 KB
testcase_19 AC 3 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <algorithm>
#include <cassert>
#include <random>
#include <iomanip>
#include <bitset>
#define FOR(i, n, m) for(ll i = n; i < (int)m; i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll inf = 1000000000;
constexpr ll mod = 998244353;
constexpr long double eps = 1e-9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;
    vector<ll> a(n);
    REP(i, n) cin >> a[i];
    string s;
    cin >> s;
    vector<ll> l, r;
    l.pb(1); r.pb(n);
    ll lp = 1, rp = n;
    REP(i, m) {
        if(lp == rp) {
            if(s[i] == 'L') {
                if(lp != 1) {
                    lp--;
                    rp--;
                }
            } else {
                if(lp != n) {
                    lp++;
                    rp++;
                }
            }
            continue;
        }
        if(s[i] == 'L') {
            if(lp == 1) {
                l.pb(l.back() + 1);
                rp--;
            } else {
                lp--;
                rp--;
            }
        } else {
            if(rp == n) {
                r.pb(r.back() - 1);
                lp++;
            } else {
                lp++;
                rp++;
            }
        }
    }
    vector<ll> ans(n, 0);
    if(lp == rp) {
        REP(i, n) ans[lp - 1] += a[i];
    } else {
    for(ll i = lp; i <= rp; i++) {
        if(i == lp) {
            REP(j, l.size()) ans[i - 1] += a[l[j] - 1];
        } else if(i == rp) {
            REP(j, r.size()) ans[i - 1] += a[r[j] - 1];
        } else {
            ans[i - 1] = a[(int)l.size() + (i - lp) - 1];
        }
    }
    }
    REP(i, n) {
        if(i) cout << " ";
        cout << ans[i];
    }
    cout << endl;
    return 0;
}
0