#include <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <set>
typedef long long llong;
const int MAXN = 400000 + 10;
const int INF = 2e9;
int n;
int w[MAXN];
int b[MAXN];
char s[MAXN];
int f[MAXN];
int fPrim[MAXN];
std::vector <std::pair <int,int>> v;
int solveFor(int k)
{
v.clear();
for (int i = 1 ; i <= n ; ++i)
{
v.push_back({std::min(w[i], b[(i + k - 1) % n + 1]), std::max(w[i], b[(i + k - 1) % n + 1])});
}
int res = 0;
std::sort(v.begin(), v.end());
for (int i = 0 ; i < n ; ++i)
{
for (int j = i + 1 ; j < n ; ++j)
{
res += (v[j].first < v[i].second && v[i].second < v[j].second);
}
}
return res;
}
void solve()
{
int cntW = 1;
int cntB = 1;
for (int i = 1 ; i <= 2 * n ; ++i)
{
if (s[i] == s[1]) w[cntW++] = i;
else b[cntB++] = i;
}
int max = 0;
for (int i = 0 ; i < n ; ++i)
{
// std::cout << "here: " << i << ' ' << solveFor(i) << '\n';
f[i] = solveFor(i);
max = std::max(max, solveFor(i));
if (i >= 1)
{
fPrim[i - 1] = f[i] - f[i];
// assert(solveFor(i) - solveFor(i - 1) >= solveFor(i + 1) - solveFor(i));
}
}
for (int i = 1 ; i < n - 2 ; ++i)
{
assert(fPrim[i - 1] - fPrim[i] >= fPrim[i] - fPrim[i + 1]);
}
std::cout << max << '\n';
}
void input()
{
std::cin >> n;
std::cin >> s + 1;
}
void fastIOI()
{
std::ios_base :: sync_with_stdio(0);
std::cout.tie(nullptr);
std::cin.tie(nullptr);
}
int main()
{
fastIOI();
input();
solve();
return 0;
}
Compilation message
monochrome.cpp: In function 'void input()':
monochrome.cpp:78:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
78 | std::cin >> s + 1;
| ~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6488 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
2 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6488 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
2 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
28 ms |
6620 KB |
Output is correct |
15 |
Correct |
27 ms |
6492 KB |
Output is correct |
16 |
Correct |
27 ms |
6488 KB |
Output is correct |
17 |
Correct |
32 ms |
6612 KB |
Output is correct |
18 |
Correct |
25 ms |
6628 KB |
Output is correct |
19 |
Correct |
24 ms |
6492 KB |
Output is correct |
20 |
Correct |
22 ms |
6488 KB |
Output is correct |
21 |
Correct |
19 ms |
6492 KB |
Output is correct |
22 |
Correct |
21 ms |
6492 KB |
Output is correct |
23 |
Correct |
9 ms |
6492 KB |
Output is correct |
24 |
Correct |
17 ms |
6624 KB |
Output is correct |
25 |
Correct |
20 ms |
6492 KB |
Output is correct |
26 |
Correct |
24 ms |
6744 KB |
Output is correct |
27 |
Correct |
22 ms |
6488 KB |
Output is correct |
28 |
Correct |
24 ms |
6624 KB |
Output is correct |
29 |
Correct |
20 ms |
6620 KB |
Output is correct |
30 |
Correct |
23 ms |
6620 KB |
Output is correct |
31 |
Correct |
23 ms |
6488 KB |
Output is correct |
32 |
Correct |
24 ms |
6492 KB |
Output is correct |
33 |
Correct |
29 ms |
6628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6488 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
2 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
28 ms |
6620 KB |
Output is correct |
15 |
Correct |
27 ms |
6492 KB |
Output is correct |
16 |
Correct |
27 ms |
6488 KB |
Output is correct |
17 |
Correct |
32 ms |
6612 KB |
Output is correct |
18 |
Correct |
25 ms |
6628 KB |
Output is correct |
19 |
Correct |
24 ms |
6492 KB |
Output is correct |
20 |
Correct |
22 ms |
6488 KB |
Output is correct |
21 |
Correct |
19 ms |
6492 KB |
Output is correct |
22 |
Correct |
21 ms |
6492 KB |
Output is correct |
23 |
Correct |
9 ms |
6492 KB |
Output is correct |
24 |
Correct |
17 ms |
6624 KB |
Output is correct |
25 |
Correct |
20 ms |
6492 KB |
Output is correct |
26 |
Correct |
24 ms |
6744 KB |
Output is correct |
27 |
Correct |
22 ms |
6488 KB |
Output is correct |
28 |
Correct |
24 ms |
6624 KB |
Output is correct |
29 |
Correct |
20 ms |
6620 KB |
Output is correct |
30 |
Correct |
23 ms |
6620 KB |
Output is correct |
31 |
Correct |
23 ms |
6488 KB |
Output is correct |
32 |
Correct |
24 ms |
6492 KB |
Output is correct |
33 |
Correct |
29 ms |
6628 KB |
Output is correct |
34 |
Execution timed out |
2008 ms |
6488 KB |
Time limit exceeded |
35 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6488 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
2 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
28 ms |
6620 KB |
Output is correct |
15 |
Correct |
27 ms |
6492 KB |
Output is correct |
16 |
Correct |
27 ms |
6488 KB |
Output is correct |
17 |
Correct |
32 ms |
6612 KB |
Output is correct |
18 |
Correct |
25 ms |
6628 KB |
Output is correct |
19 |
Correct |
24 ms |
6492 KB |
Output is correct |
20 |
Correct |
22 ms |
6488 KB |
Output is correct |
21 |
Correct |
19 ms |
6492 KB |
Output is correct |
22 |
Correct |
21 ms |
6492 KB |
Output is correct |
23 |
Correct |
9 ms |
6492 KB |
Output is correct |
24 |
Correct |
17 ms |
6624 KB |
Output is correct |
25 |
Correct |
20 ms |
6492 KB |
Output is correct |
26 |
Correct |
24 ms |
6744 KB |
Output is correct |
27 |
Correct |
22 ms |
6488 KB |
Output is correct |
28 |
Correct |
24 ms |
6624 KB |
Output is correct |
29 |
Correct |
20 ms |
6620 KB |
Output is correct |
30 |
Correct |
23 ms |
6620 KB |
Output is correct |
31 |
Correct |
23 ms |
6488 KB |
Output is correct |
32 |
Correct |
24 ms |
6492 KB |
Output is correct |
33 |
Correct |
29 ms |
6628 KB |
Output is correct |
34 |
Execution timed out |
2008 ms |
6488 KB |
Time limit exceeded |
35 |
Halted |
0 ms |
0 KB |
- |