#include <bits/stdc++.h>
using namespace std;
const int N = 400000 + 7;
int n;
string s;
int main() {
ios::sync_with_stdio(0); cin.tie(0);
cin >> n >> s;
assert((int) s.size() == 2 * n);
function<int(vector<int>, vector<int>)> compute = [&] (vector<int> l, vector<int> r) {
assert((int) l.size() == n);
assert((int) r.size() == n);
int sol = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j <= n; j++) {
if (min(l[i], r[i]) < min(l[j], r[j]) && min(l[j], r[j]) < max(l[i], r[i]) && max(l[i], r[i]) < max(l[j], r[j])) {
sol++;
}
}
}
return sol;
};
function<vector<int>(vector<int>, int)> shift = [&] (vector<int> a, int cnt) {
vector<int> b((int) a.size());
for (int i = 0; i < (int) a.size(); i++) {
b[(i + cnt) % (int) a.size()] = a[i];
}
return b;
};
vector<int> a, b;
for (int i = 0; i < 2 * n; i++) {
if (s[i] != s[0]) {
a.push_back(i);
} else {
b.push_back(i);
}
}
int sol = compute(a, b);
for (int cnt = 1; cnt < n; cnt++) {
sol = max(sol, compute(a, shift(b, cnt)));
}
cout << sol << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
43 ms |
300 KB |
Output is correct |
15 |
Correct |
40 ms |
296 KB |
Output is correct |
16 |
Correct |
39 ms |
300 KB |
Output is correct |
17 |
Correct |
41 ms |
204 KB |
Output is correct |
18 |
Correct |
28 ms |
204 KB |
Output is correct |
19 |
Correct |
31 ms |
332 KB |
Output is correct |
20 |
Correct |
31 ms |
204 KB |
Output is correct |
21 |
Correct |
28 ms |
204 KB |
Output is correct |
22 |
Correct |
29 ms |
324 KB |
Output is correct |
23 |
Correct |
12 ms |
316 KB |
Output is correct |
24 |
Correct |
29 ms |
332 KB |
Output is correct |
25 |
Correct |
24 ms |
204 KB |
Output is correct |
26 |
Correct |
29 ms |
308 KB |
Output is correct |
27 |
Correct |
32 ms |
204 KB |
Output is correct |
28 |
Correct |
38 ms |
204 KB |
Output is correct |
29 |
Correct |
27 ms |
204 KB |
Output is correct |
30 |
Correct |
26 ms |
208 KB |
Output is correct |
31 |
Correct |
41 ms |
296 KB |
Output is correct |
32 |
Correct |
42 ms |
300 KB |
Output is correct |
33 |
Correct |
38 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
43 ms |
300 KB |
Output is correct |
15 |
Correct |
40 ms |
296 KB |
Output is correct |
16 |
Correct |
39 ms |
300 KB |
Output is correct |
17 |
Correct |
41 ms |
204 KB |
Output is correct |
18 |
Correct |
28 ms |
204 KB |
Output is correct |
19 |
Correct |
31 ms |
332 KB |
Output is correct |
20 |
Correct |
31 ms |
204 KB |
Output is correct |
21 |
Correct |
28 ms |
204 KB |
Output is correct |
22 |
Correct |
29 ms |
324 KB |
Output is correct |
23 |
Correct |
12 ms |
316 KB |
Output is correct |
24 |
Correct |
29 ms |
332 KB |
Output is correct |
25 |
Correct |
24 ms |
204 KB |
Output is correct |
26 |
Correct |
29 ms |
308 KB |
Output is correct |
27 |
Correct |
32 ms |
204 KB |
Output is correct |
28 |
Correct |
38 ms |
204 KB |
Output is correct |
29 |
Correct |
27 ms |
204 KB |
Output is correct |
30 |
Correct |
26 ms |
208 KB |
Output is correct |
31 |
Correct |
41 ms |
296 KB |
Output is correct |
32 |
Correct |
42 ms |
300 KB |
Output is correct |
33 |
Correct |
38 ms |
204 KB |
Output is correct |
34 |
Execution timed out |
2080 ms |
332 KB |
Time limit exceeded |
35 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
43 ms |
300 KB |
Output is correct |
15 |
Correct |
40 ms |
296 KB |
Output is correct |
16 |
Correct |
39 ms |
300 KB |
Output is correct |
17 |
Correct |
41 ms |
204 KB |
Output is correct |
18 |
Correct |
28 ms |
204 KB |
Output is correct |
19 |
Correct |
31 ms |
332 KB |
Output is correct |
20 |
Correct |
31 ms |
204 KB |
Output is correct |
21 |
Correct |
28 ms |
204 KB |
Output is correct |
22 |
Correct |
29 ms |
324 KB |
Output is correct |
23 |
Correct |
12 ms |
316 KB |
Output is correct |
24 |
Correct |
29 ms |
332 KB |
Output is correct |
25 |
Correct |
24 ms |
204 KB |
Output is correct |
26 |
Correct |
29 ms |
308 KB |
Output is correct |
27 |
Correct |
32 ms |
204 KB |
Output is correct |
28 |
Correct |
38 ms |
204 KB |
Output is correct |
29 |
Correct |
27 ms |
204 KB |
Output is correct |
30 |
Correct |
26 ms |
208 KB |
Output is correct |
31 |
Correct |
41 ms |
296 KB |
Output is correct |
32 |
Correct |
42 ms |
300 KB |
Output is correct |
33 |
Correct |
38 ms |
204 KB |
Output is correct |
34 |
Execution timed out |
2080 ms |
332 KB |
Time limit exceeded |
35 |
Halted |
0 ms |
0 KB |
- |