#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);
for (int i = 0; i < n; i++) {
if (l[i] > r[i]) {
swap(l[i], r[i]);
}
}
int sol = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j <= n; j++) {
if (l[i] < l[j] && l[j] < r[i] && r[i] < r[j]) {
sol++;
}
}
}
return sol;
};
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 shift = 1; shift < n; shift++) {
vector<int> newB;
for (int i = 1; i < n; i++) {
newB.push_back(b[i]);
}
newB.push_back(b[0]);
b = newB;
sol = max(sol, compute(a, b));
}
cout << sol << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
316 KB |
Output is correct |
6 |
Correct |
1 ms |
320 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
0 ms |
208 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
0 ms |
208 KB |
Output is correct |
11 |
Correct |
0 ms |
208 KB |
Output is correct |
12 |
Correct |
0 ms |
316 KB |
Output is correct |
13 |
Correct |
0 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
316 KB |
Output is correct |
6 |
Correct |
1 ms |
320 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
0 ms |
208 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
0 ms |
208 KB |
Output is correct |
11 |
Correct |
0 ms |
208 KB |
Output is correct |
12 |
Correct |
0 ms |
316 KB |
Output is correct |
13 |
Correct |
0 ms |
208 KB |
Output is correct |
14 |
Correct |
28 ms |
308 KB |
Output is correct |
15 |
Correct |
32 ms |
312 KB |
Output is correct |
16 |
Correct |
30 ms |
208 KB |
Output is correct |
17 |
Correct |
38 ms |
308 KB |
Output is correct |
18 |
Correct |
21 ms |
208 KB |
Output is correct |
19 |
Correct |
22 ms |
208 KB |
Output is correct |
20 |
Correct |
23 ms |
324 KB |
Output is correct |
21 |
Correct |
19 ms |
336 KB |
Output is correct |
22 |
Correct |
26 ms |
320 KB |
Output is correct |
23 |
Correct |
9 ms |
208 KB |
Output is correct |
24 |
Correct |
19 ms |
324 KB |
Output is correct |
25 |
Correct |
24 ms |
324 KB |
Output is correct |
26 |
Correct |
23 ms |
328 KB |
Output is correct |
27 |
Correct |
28 ms |
328 KB |
Output is correct |
28 |
Correct |
29 ms |
316 KB |
Output is correct |
29 |
Correct |
20 ms |
324 KB |
Output is correct |
30 |
Correct |
19 ms |
208 KB |
Output is correct |
31 |
Correct |
29 ms |
324 KB |
Output is correct |
32 |
Correct |
26 ms |
320 KB |
Output is correct |
33 |
Correct |
29 ms |
312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
316 KB |
Output is correct |
6 |
Correct |
1 ms |
320 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
0 ms |
208 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
0 ms |
208 KB |
Output is correct |
11 |
Correct |
0 ms |
208 KB |
Output is correct |
12 |
Correct |
0 ms |
316 KB |
Output is correct |
13 |
Correct |
0 ms |
208 KB |
Output is correct |
14 |
Correct |
28 ms |
308 KB |
Output is correct |
15 |
Correct |
32 ms |
312 KB |
Output is correct |
16 |
Correct |
30 ms |
208 KB |
Output is correct |
17 |
Correct |
38 ms |
308 KB |
Output is correct |
18 |
Correct |
21 ms |
208 KB |
Output is correct |
19 |
Correct |
22 ms |
208 KB |
Output is correct |
20 |
Correct |
23 ms |
324 KB |
Output is correct |
21 |
Correct |
19 ms |
336 KB |
Output is correct |
22 |
Correct |
26 ms |
320 KB |
Output is correct |
23 |
Correct |
9 ms |
208 KB |
Output is correct |
24 |
Correct |
19 ms |
324 KB |
Output is correct |
25 |
Correct |
24 ms |
324 KB |
Output is correct |
26 |
Correct |
23 ms |
328 KB |
Output is correct |
27 |
Correct |
28 ms |
328 KB |
Output is correct |
28 |
Correct |
29 ms |
316 KB |
Output is correct |
29 |
Correct |
20 ms |
324 KB |
Output is correct |
30 |
Correct |
19 ms |
208 KB |
Output is correct |
31 |
Correct |
29 ms |
324 KB |
Output is correct |
32 |
Correct |
26 ms |
320 KB |
Output is correct |
33 |
Correct |
29 ms |
312 KB |
Output is correct |
34 |
Execution timed out |
2062 ms |
312 KB |
Time limit exceeded |
35 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
316 KB |
Output is correct |
6 |
Correct |
1 ms |
320 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
0 ms |
208 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
0 ms |
208 KB |
Output is correct |
11 |
Correct |
0 ms |
208 KB |
Output is correct |
12 |
Correct |
0 ms |
316 KB |
Output is correct |
13 |
Correct |
0 ms |
208 KB |
Output is correct |
14 |
Correct |
28 ms |
308 KB |
Output is correct |
15 |
Correct |
32 ms |
312 KB |
Output is correct |
16 |
Correct |
30 ms |
208 KB |
Output is correct |
17 |
Correct |
38 ms |
308 KB |
Output is correct |
18 |
Correct |
21 ms |
208 KB |
Output is correct |
19 |
Correct |
22 ms |
208 KB |
Output is correct |
20 |
Correct |
23 ms |
324 KB |
Output is correct |
21 |
Correct |
19 ms |
336 KB |
Output is correct |
22 |
Correct |
26 ms |
320 KB |
Output is correct |
23 |
Correct |
9 ms |
208 KB |
Output is correct |
24 |
Correct |
19 ms |
324 KB |
Output is correct |
25 |
Correct |
24 ms |
324 KB |
Output is correct |
26 |
Correct |
23 ms |
328 KB |
Output is correct |
27 |
Correct |
28 ms |
328 KB |
Output is correct |
28 |
Correct |
29 ms |
316 KB |
Output is correct |
29 |
Correct |
20 ms |
324 KB |
Output is correct |
30 |
Correct |
19 ms |
208 KB |
Output is correct |
31 |
Correct |
29 ms |
324 KB |
Output is correct |
32 |
Correct |
26 ms |
320 KB |
Output is correct |
33 |
Correct |
29 ms |
312 KB |
Output is correct |
34 |
Execution timed out |
2062 ms |
312 KB |
Time limit exceeded |
35 |
Halted |
0 ms |
0 KB |
- |