def ants(n, w): r = [0 for i in range(n)] an = [i + 1 for i in range(n)] e = ''.join(sorted(w)) while w != e: for i in range(len(an)): if w[i] == 'L': an[i] = an[i] - 0.5 else: an[i] = an[i] + 0.5 for i in range(len(an) - 1): if an[i] == an[i + 1]: r[i] += 1 r[i + 1] += 1 w = w[:i] + w[i + 1] + w[i] + w[i + 2:] re = "" for i in r: re += f"{i} " return re[:-1] if __name__ == "__main__" : n = int(input()) w = input() print(ants(n, 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 | def ants(n, w): r = [0 for i in range(n)] an = [i + 1 for i in range(n)] e = ''.join(sorted(w)) while w != e: for i in range(len(an)): if w[i] == 'L': an[i] = an[i] - 0.5 else: an[i] = an[i] + 0.5 for i in range(len(an) - 1): if an[i] == an[i + 1]: r[i] += 1 r[i + 1] += 1 w = w[:i] + w[i + 1] + w[i] + w[i + 2:] re = "" for i in r: re += f"{i} " return re[:-1] if __name__ == "__main__" : n = int(input()) w = input() print(ants(n, w)) |