#include <iostream>
#include <vector>
#include <string>
#include <functional>
#include <cassert>
using namespace std;
typedef long long ll;
const int N = 400000 + 7;
int n;
string s;
int main() {
ios::sync_with_stdio(0); cin.tie(0);
cin >> n >> s;
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);
}
}
vector<ll> cnt(n);
ll sol = 0;
for (int shift = 0; shift < n; shift++) {
for (int i = 0; i < n; i++) {
int i2 = (i + shift) % n, l = min(a[i], b[i2]), r = max(a[i], b[i2]);
for (int j = 0; j < n; j++) {
int j2 = (j + shift) % n;
if (l < min(a[j], b[j2]) && min(a[j], b[j2]) < r && r < max(a[j], b[j2])) {
cnt[shift]++;
}
}
}
}
for (auto& x : cnt) {
sol = max(sol, x);
}
cout << sol << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
224 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 |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
0 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
224 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 |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
0 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 |
126 ms |
296 KB |
Output is correct |
15 |
Correct |
129 ms |
204 KB |
Output is correct |
16 |
Correct |
124 ms |
204 KB |
Output is correct |
17 |
Correct |
125 ms |
300 KB |
Output is correct |
18 |
Correct |
89 ms |
300 KB |
Output is correct |
19 |
Correct |
102 ms |
304 KB |
Output is correct |
20 |
Correct |
103 ms |
300 KB |
Output is correct |
21 |
Correct |
91 ms |
300 KB |
Output is correct |
22 |
Correct |
96 ms |
300 KB |
Output is correct |
23 |
Correct |
37 ms |
204 KB |
Output is correct |
24 |
Correct |
86 ms |
204 KB |
Output is correct |
25 |
Correct |
80 ms |
204 KB |
Output is correct |
26 |
Correct |
95 ms |
204 KB |
Output is correct |
27 |
Correct |
103 ms |
204 KB |
Output is correct |
28 |
Correct |
121 ms |
300 KB |
Output is correct |
29 |
Correct |
87 ms |
292 KB |
Output is correct |
30 |
Correct |
91 ms |
296 KB |
Output is correct |
31 |
Correct |
129 ms |
300 KB |
Output is correct |
32 |
Correct |
129 ms |
204 KB |
Output is correct |
33 |
Correct |
129 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
224 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 |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
0 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 |
126 ms |
296 KB |
Output is correct |
15 |
Correct |
129 ms |
204 KB |
Output is correct |
16 |
Correct |
124 ms |
204 KB |
Output is correct |
17 |
Correct |
125 ms |
300 KB |
Output is correct |
18 |
Correct |
89 ms |
300 KB |
Output is correct |
19 |
Correct |
102 ms |
304 KB |
Output is correct |
20 |
Correct |
103 ms |
300 KB |
Output is correct |
21 |
Correct |
91 ms |
300 KB |
Output is correct |
22 |
Correct |
96 ms |
300 KB |
Output is correct |
23 |
Correct |
37 ms |
204 KB |
Output is correct |
24 |
Correct |
86 ms |
204 KB |
Output is correct |
25 |
Correct |
80 ms |
204 KB |
Output is correct |
26 |
Correct |
95 ms |
204 KB |
Output is correct |
27 |
Correct |
103 ms |
204 KB |
Output is correct |
28 |
Correct |
121 ms |
300 KB |
Output is correct |
29 |
Correct |
87 ms |
292 KB |
Output is correct |
30 |
Correct |
91 ms |
296 KB |
Output is correct |
31 |
Correct |
129 ms |
300 KB |
Output is correct |
32 |
Correct |
129 ms |
204 KB |
Output is correct |
33 |
Correct |
129 ms |
204 KB |
Output is correct |
34 |
Execution timed out |
2086 ms |
332 KB |
Time limit exceeded |
35 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
224 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 |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
0 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 |
126 ms |
296 KB |
Output is correct |
15 |
Correct |
129 ms |
204 KB |
Output is correct |
16 |
Correct |
124 ms |
204 KB |
Output is correct |
17 |
Correct |
125 ms |
300 KB |
Output is correct |
18 |
Correct |
89 ms |
300 KB |
Output is correct |
19 |
Correct |
102 ms |
304 KB |
Output is correct |
20 |
Correct |
103 ms |
300 KB |
Output is correct |
21 |
Correct |
91 ms |
300 KB |
Output is correct |
22 |
Correct |
96 ms |
300 KB |
Output is correct |
23 |
Correct |
37 ms |
204 KB |
Output is correct |
24 |
Correct |
86 ms |
204 KB |
Output is correct |
25 |
Correct |
80 ms |
204 KB |
Output is correct |
26 |
Correct |
95 ms |
204 KB |
Output is correct |
27 |
Correct |
103 ms |
204 KB |
Output is correct |
28 |
Correct |
121 ms |
300 KB |
Output is correct |
29 |
Correct |
87 ms |
292 KB |
Output is correct |
30 |
Correct |
91 ms |
296 KB |
Output is correct |
31 |
Correct |
129 ms |
300 KB |
Output is correct |
32 |
Correct |
129 ms |
204 KB |
Output is correct |
33 |
Correct |
129 ms |
204 KB |
Output is correct |
34 |
Execution timed out |
2086 ms |
332 KB |
Time limit exceeded |
35 |
Halted |
0 ms |
0 KB |
- |