[BOJ 13055] K-Inversions

View as PDF

Submit solution

Points: 5
Time limit: 10.0s
Memory limit: 512M

Problem types
Allowed languages
Assembly, Awk, C, C++, Java, Pascal, Perl, Python, Sed, Text

You are given a string s consisting only of upper case letters A and B. For an integer k, a pair of indices i and j (1 ≤ i < j ≤ n) is called a k-inversion if and only if s[i] = B, s[j] = A and j − i = k.</p>

Consider the string BABA. It has two 1-inversions and one 3-inversion. It has no 2-inversions.

For each k between 1 and n − 1 (inclusive), print the number of k-inversions in the string s.

입력 형식

Each input will consist of a single test case. Note that your program may be run multiple times on different inputs. The input will consist of a single line with a string s, which consists of only upper case As and Bs. The string s will be between 1 and 1,000,000 characters long. There will be no spaces.

출력 형식

Output n − 1 lines, each with a single integer. The first line’s integer should be the number of 1-inversions, the second should be the number of 2-inversions, and so on.

예제 입력 1

BABA

예제 출력 1

2
0
1

예제 입력 2

BBBBBAAAAA

예제 출력 2

1
2
3
4
5
4
3
2
1

Comments

There are no comments at the moment.