結果
問題 |
No.1021 Children in Classrooms
|
ユーザー |
|
提出日時 | 2020-04-26 09:42:35 |
言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 66 ms / 2,000 ms |
コード長 | 1,451 bytes |
コンパイル時間 | 760 ms |
コンパイル使用メモリ | 123,904 KB |
実行使用メモリ | 5,432 KB |
最終ジャッジ日時 | 2024-11-30 17:45:20 |
合計ジャッジ時間 | 2,598 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
ソースコード
#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; }