Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define int long long
- #define double long double
- #define pb push_back
- #define randGen mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
- const int INF = 1e18;
- const int MOD = 1e9 + 7;
- signed main() {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- cout.tie(NULL);
- int t;
- cin >> t;
- while (t--) {
- int n;
- cin >> n;
- vector<int> pref1(n, 0), pref2(n, 0);
- for (int i = 0; i < n; ++i) {
- char h;
- cin >> h;
- if (h == 'D') {
- pref1[i]++;
- } else {
- pref2[i]++;
- }
- }
- for (int i = 1; i < n; ++i) {
- pref1[i] += pref1[i - 1];
- pref2[i] += pref2[i - 1];
- }
- map<pair<int, int>, int> a;
- for (int i = 0; i < n; ++i) {
- int d = pref1[i], k = pref2[i];
- int maxi = 1;
- if (d == 0) {
- for (int j = 1; j * j <= k; ++j) {
- if (k % j == 0) {
- a[{0, j}]++;
- maxi = max(maxi, a[{0, j}]);
- if (j == k / j) {
- continue;
- }
- a[{0, k / j}]++;
- maxi = max(maxi, a[{0, k / j}]);
- }
- }
- }
- for (int j = 1; j * j <= d; ++j) {
- int ind1 = -1, ind2 = -1;
- if (d % j == 0 && k % j == 0) {
- ind1 = d / j;
- ind2 = k / j;
- a[{d / j, k / j}]++;
- maxi = max(maxi, a[{d / j, k / j}]);
- }
- if (d % j == 0 && k % (d / j) == 0 && (j != ind1 || k / (d / j) != ind2)) {
- int h = d / j;
- a[{j, k / h}]++;
- maxi = max(maxi, a[{j, k / h}]);
- }
- }
- cout << maxi << ' ';
- }
- cout << '\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement