#include <cstdio> #include <algorithm> #define REP(a, n) for (int a = 0; a < (n); ++a) #define FOR(a, b, c) for (int a = (b); a <= (c); ++a) typedef long long LL; using namespace std; ////////////////////// int N, ileL, curL; char tab[300'005]; int main() { scanf("%d%s", &N, tab); REP(a, N) if (tab[a]=='L') ++ileL; REP(a, N) { int zL = a-curL; if (tab[a]=='L') ++curL; int zP = ileL-curL; int res = 2*min(zL, zP); if ((tab[a]=='L' && zL>zP) || (tab[a]=='P' && zP>zL)) ++res; printf("%d%c", res, a==N-1 ? '\n' : ' '); } }
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 | #include <cstdio> #include <algorithm> #define REP(a, n) for (int a = 0; a < (n); ++a) #define FOR(a, b, c) for (int a = (b); a <= (c); ++a) typedef long long LL; using namespace std; ////////////////////// int N, ileL, curL; char tab[300'005]; int main() { scanf("%d%s", &N, tab); REP(a, N) if (tab[a]=='L') ++ileL; REP(a, N) { int zL = a-curL; if (tab[a]=='L') ++curL; int zP = ileL-curL; int res = 2*min(zL, zP); if ((tab[a]=='L' && zL>zP) || (tab[a]=='P' && zP>zL)) ++res; printf("%d%c", res, a==N-1 ? '\n' : ' '); } } |