#include <algorithm>> #include <iostream> using namespace std; int N; char tab[300001]; pair<int, int> lp[300001]; int maxl = 0, maxp = 0; int main() { cin >> N; scanf("%c", tab + 1); for (int i = 1; i < N + 1; ++i) { scanf("%c", tab + i); if (tab[i] == 'L') { lp[i + 1].first = 1 + lp[i].first; lp[i + 1].second = lp[i].second; maxl++; } else { lp[i + 1].first = lp[i].first; lp[i + 1].second = lp[i].second + 1; maxp++; } } for (int i = 1; i < N + 1; ++i) { if (tab[i] == 'L') { if (lp[i].second == 0) cout << 0 << " "; else { if (maxl - lp[i].first - 1 == 0) cout << 1 << " "; else { if (lp[i].second == maxl - lp[i].first - 1) { cout << lp[i].second * 2 << " "; } else { if (lp[i].second > maxl - lp[i].first - 1) { cout << (maxl - lp[i].first - 1) * 2 + 1 << " "; } else { cout << lp[i].second * 2 << " "; } } } } } else { if (maxl - lp[i].first == 0) cout << 0 << " "; else { if (lp[i].second == 0) cout << 1 << " "; else { if (lp[i].second == maxl - lp[i].first) { cout << lp[i].second * 2 << " "; } else { if (lp[i].second > maxl - lp[i].first) cout << (maxl - lp[i].first) * 2 << " "; else { cout << lp[i].second * 2 + 1 << " "; } } } } } } 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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | #include <algorithm>> #include <iostream> using namespace std; int N; char tab[300001]; pair<int, int> lp[300001]; int maxl = 0, maxp = 0; int main() { cin >> N; scanf("%c", tab + 1); for (int i = 1; i < N + 1; ++i) { scanf("%c", tab + i); if (tab[i] == 'L') { lp[i + 1].first = 1 + lp[i].first; lp[i + 1].second = lp[i].second; maxl++; } else { lp[i + 1].first = lp[i].first; lp[i + 1].second = lp[i].second + 1; maxp++; } } for (int i = 1; i < N + 1; ++i) { if (tab[i] == 'L') { if (lp[i].second == 0) cout << 0 << " "; else { if (maxl - lp[i].first - 1 == 0) cout << 1 << " "; else { if (lp[i].second == maxl - lp[i].first - 1) { cout << lp[i].second * 2 << " "; } else { if (lp[i].second > maxl - lp[i].first - 1) { cout << (maxl - lp[i].first - 1) * 2 + 1 << " "; } else { cout << lp[i].second * 2 << " "; } } } } } else { if (maxl - lp[i].first == 0) cout << 0 << " "; else { if (lp[i].second == 0) cout << 1 << " "; else { if (lp[i].second == maxl - lp[i].first) { cout << lp[i].second * 2 << " "; } else { if (lp[i].second > maxl - lp[i].first) cout << (maxl - lp[i].first) * 2 << " "; else { cout << lp[i].second * 2 + 1 << " "; } } } } } } return 0; } |