42 lines
780 B
C++
42 lines
780 B
C++
#include <cstring>
|
|
#include <iostream>
|
|
|
|
using namespace std;
|
|
|
|
constexpr int MAX_N = 1e6 + 5;
|
|
int max_period[MAX_N];
|
|
|
|
void log_array(const int arr[], const size_t n) {
|
|
for (size_t i = 0; i < n; i++) {
|
|
clog << arr[i] << " ";
|
|
}
|
|
clog << endl;
|
|
}
|
|
|
|
void solve(string s) {
|
|
memset(max_period, 0, sizeof(max_period));
|
|
max_period[0] = 1;
|
|
for (int i = 1; i < s.size(); i++) {
|
|
if (s[i - max_period[i - 1]] == s[i]) {
|
|
max_period[i] = max_period[i - 1];
|
|
} else {
|
|
max_period[i] = i + 1;
|
|
}
|
|
}
|
|
log_array(max_period, s.size());
|
|
}
|
|
|
|
int main() {
|
|
ios::sync_with_stdio(false);
|
|
cin.tie(nullptr);
|
|
|
|
int n;
|
|
string s;
|
|
while (cin >> n && n) {
|
|
cin >> s;
|
|
solve(s);
|
|
}
|
|
|
|
return 0;
|
|
}
|