import sys QQDBG = False if __name__=='__main__': n = int(sys.stdin.readline()) T = sys.stdin.readline() W = [0]*n s, l, p = 0, 0, 0 for i in range(n): if T[i] == 'P': W[i] = -s p += 1 s = 0 elif T[i] == 'L': if p > 0: j = i-p W[j] += 1 W[j+1] += 1 s += 2 if p > 1 else 1 W[i] = -s+1 s = 1 else: W[i] = -s s = 0 l += 1 if QQDBG: D = [0]*n D[0] = W[0] for j in range(i): D[j+1] = D[j] + W[j+1] print(i, T[i], ':', l, p, s, ':', ' '.join(map(str, W[:(i+1)])), '::', ' '.join(map(str, D[:(i+1)]))) for i in range(n-1): W[i+1] += W[i] print(' '.join(map(str, W)))
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 | import sys QQDBG = False if __name__=='__main__': n = int(sys.stdin.readline()) T = sys.stdin.readline() W = [0]*n s, l, p = 0, 0, 0 for i in range(n): if T[i] == 'P': W[i] = -s p += 1 s = 0 elif T[i] == 'L': if p > 0: j = i-p W[j] += 1 W[j+1] += 1 s += 2 if p > 1 else 1 W[i] = -s+1 s = 1 else: W[i] = -s s = 0 l += 1 if QQDBG: D = [0]*n D[0] = W[0] for j in range(i): D[j+1] = D[j] + W[j+1] print(i, T[i], ':', l, p, s, ':', ' '.join(map(str, W[:(i+1)])), '::', ' '.join(map(str, D[:(i+1)]))) for i in range(n-1): W[i+1] += W[i] print(' '.join(map(str, W))) |