結果

問題 No.1021 Children in Classrooms
ユーザー tapienrutapienru
提出日時 2020-05-17 17:51:23
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 1,021 bytes
コンパイル時間 4,089 ms
コンパイル使用メモリ 202,908 KB
実行使用メモリ 4,824 KB
最終ジャッジ日時 2023-10-26 02:54:14
合計ジャッジ時間 6,690 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 35 ms
4,824 KB
testcase_10 AC 35 ms
4,824 KB
testcase_11 AC 34 ms
4,824 KB
testcase_12 AC 33 ms
4,824 KB
testcase_13 AC 33 ms
4,824 KB
testcase_14 AC 33 ms
4,824 KB
testcase_15 AC 25 ms
4,560 KB
testcase_16 AC 25 ms
4,560 KB
testcase_17 AC 26 ms
4,560 KB
testcase_18 AC 33 ms
4,824 KB
testcase_19 AC 7 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n, m; cin >> n >> m;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    int l = 0, r = n - 1, szl = 1, szr = 1;
    while (m--) {
        char c; cin >> c;
        if (c == 'L') {
            if (!l) {
                if (l + 1 == r) szl += szr, szr = 0;
                else if (l != r) ++szl;
            }
            if (l) --l;
            if (r) --r;
        }
        else {
            if (r >= n - 1) {
                if (l + 1 == r) szr += szl, szl = 0;
                else if (l != r) ++szr;
            }
            if (l < n - 1) ++l;
            if (r < n - 1) ++r;
        }
    }
    int i = 0;
    vector<int> ans(n);
    for (; i < szl; ++i)
        ans[l] += a[i];
    for (; i < n - szr; ++i)
        ans[++l] = a[i];
    for (; i < n; ++i)
        ans[r] += a[i];
    for (auto p : ans) cout << p << ' '; cout << '\n';
}
0