結果

問題 No.1021 Children in Classrooms
ユーザー gemmarogemmaro
提出日時 2020-04-26 09:42:35
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 67 ms / 2,000 ms
コード長 1,451 bytes
コンパイル時間 964 ms
コンパイル使用メモリ 86,728 KB
実行使用メモリ 5,232 KB
最終ジャッジ日時 2023-08-20 14:54:18
合計ジャッジ時間 2,928 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 64 ms
5,204 KB
testcase_10 AC 64 ms
5,184 KB
testcase_11 AC 63 ms
5,148 KB
testcase_12 AC 62 ms
5,232 KB
testcase_13 AC 63 ms
5,172 KB
testcase_14 AC 63 ms
5,172 KB
testcase_15 AC 47 ms
4,680 KB
testcase_16 AC 47 ms
4,620 KB
testcase_17 AC 50 ms
4,628 KB
testcase_18 AC 67 ms
4,844 KB
testcase_19 AC 8 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <deque>
#include <iostream>
#include <string>

/**
 * @sa
 * https://marycore.jp/prog/cpp/vector-join/#join%E9%96%A2%E6%95%B0%E3%81%AE%E8%87%AA%E4%BD%9C
 *
 * To use for deque, some modification is added.
 */
std::string join(const std::deque<int32_t>& d, const char* delim = 0) {
    std::string s;
    if (!d.empty()) {
        s += std::to_string(d[0]);
        for (decltype(d.size()) i = 1, c = d.size(); i < c; ++i) {
            if (delim) s += delim;
            s += std::to_string(d[i]);
        }
    }
    return s;
}

std::string solve(std::deque<int32_t>& d, const std::string& s) {
    for (auto c : s) {
        if (c == 'L') {
            const int32_t a = d[0];
            const int32_t b = d[1];
            d.pop_front();
            d.pop_front();
            d.push_front(a + b);
            d.push_back(0);
        } else {  // `c == 'R'`
            const int32_t a = d[d.size() - 1];
            const int32_t b = d[d.size() - 2];
            d.pop_back();
            d.pop_back();
            d.push_back(a + b);
            d.push_front(0);
        }
    }

    return join(d, " ");
}

int32_t main() {
    int32_t n, _m;
    std::cin >> n >> _m;

    std::deque<int32_t> d{};
    for (int32_t i = 0; i < n; ++i) {
        int32_t a;
        std::cin >> a;
        d.push_back(a);
    }

    std::string s{};
    std::cin >> s;

    const std::string result = solve(d, s);

    std::cout << result << std::endl;
}
0