#include <iostream> #include <cstring> #include <vector> using namespace std; int main(int argc, char* argv[]) { #ifdef _DEBUG freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout); #endif int n; cin >> n; static char buff[300100]; cin >> buff; vector<int> num_rights_at_left(n, 0); vector<int> num_lefts_at_right(n, 0); int curr_right_before = 0; for (int i = 0; i < n; i++) { num_rights_at_left[i] = curr_right_before; if (buff[i] == 'P') curr_right_before++; }; int tot_right = curr_right_before; int curr_left_after = 0; for (int i = n-1; i >= 0; i--) { num_lefts_at_right[i] = curr_left_after; if (buff[i] == 'L') curr_left_after++; }; int tot_left = curr_left_after; #ifdef _DEBUG if (tot_right + tot_left != n) _DEBUG_ERROR("tot_right + curr_left_after != n"); #endif vector<int> res(n); for (int i = 0; i < tot_left; i++) { // finally moving left res[i] = 2 * num_rights_at_left[i]; if (buff[i] == 'P') res[i]++; } for (int i = tot_left; i < n; i++) { // finally moving right res[i] = 2 * num_lefts_at_right[i]; if (buff[i] == 'L') res[i]++; } cout << res[0]; for (int i = 1; i < n; i++) cout << " " << res[i]; cout << "\n"; return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | #include <iostream> #include <cstring> #include <vector> using namespace std; int main(int argc, char* argv[]) { #ifdef _DEBUG freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout); #endif int n; cin >> n; static char buff[300100]; cin >> buff; vector<int> num_rights_at_left(n, 0); vector<int> num_lefts_at_right(n, 0); int curr_right_before = 0; for (int i = 0; i < n; i++) { num_rights_at_left[i] = curr_right_before; if (buff[i] == 'P') curr_right_before++; }; int tot_right = curr_right_before; int curr_left_after = 0; for (int i = n-1; i >= 0; i--) { num_lefts_at_right[i] = curr_left_after; if (buff[i] == 'L') curr_left_after++; }; int tot_left = curr_left_after; #ifdef _DEBUG if (tot_right + tot_left != n) _DEBUG_ERROR("tot_right + curr_left_after != n"); #endif vector<int> res(n); for (int i = 0; i < tot_left; i++) { // finally moving left res[i] = 2 * num_rights_at_left[i]; if (buff[i] == 'P') res[i]++; } for (int i = tot_left; i < n; i++) { // finally moving right res[i] = 2 * num_lefts_at_right[i]; if (buff[i] == 'L') res[i]++; } cout << res[0]; for (int i = 1; i < n; i++) cout << " " << res[i]; cout << "\n"; return 0; } |