結果
問題 |
No.1021 Children in Classrooms
|
ユーザー |
![]() |
提出日時 | 2020-04-18 17:23:04 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 122 ms / 2,000 ms |
コード長 | 1,284 bytes |
コンパイル時間 | 2,232 ms |
コンパイル使用メモリ | 195,180 KB |
最終ジャッジ日時 | 2025-01-09 21:11:50 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
ソースコード
#include <bits/stdc++.h> using namespace std; enum pos { L, M, R }; int main() { int N, M; cin >> N >> M; vector<int> A(N); for(auto &e : A) cin >> e; string S; cin >> S; auto side = [&](int x) -> int { if(x == 0) return pos::L; if(x == N - 1) return pos::R; for(auto &c : S) { if(c == 'L') x--; else x++; if(x == 0) return pos::L; if(x == N - 1) return pos::R; } return pos::M; }; int L, R; int l = 0, r = N; while(r - l > 1) { int c = (l + r) / 2; if(side(c) == pos::L) l = c; else r = c; } L = l; l = -1, r = N - 1; while(r - l > 1) { int c = (l + r) / 2; if(side(c) == pos::R) r = c; else l = c; } R = r; auto end = [&](int x) -> int { for(auto &c : S) { if(c == 'L') x = max(0, x - 1); else x = min(N - 1, x + 1); } return x; }; vector<int> ans(N); int a = end(L), b = end(R); for(int i = L; i >= 0; --i) ans[a] += A[i]; for(int i = L + 1; i < R; ++i) ans[++a] = A[i]; for(int i = R; i < N; ++i) ans[b] += A[i]; for(int i = 0; i < N; ++i) cout << ans[i] << " "; cout << '\n'; return 0; }