#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++) {
for (int j = 0; j < n; j++) {
if (min(a[i], b[(i + shift) % n]) < min(a[j], b[(j + shift) % n]) && min(a[j], b[(j + shift) % n]) < max(a[i], b[(i + shift) % n]) && max(a[i], b[(i + shift) % n]) < max(a[j], b[(j + shift) % n])) {
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 |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 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 |
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 |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 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 |
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 |
145 ms |
300 KB |
Output is correct |
15 |
Correct |
147 ms |
304 KB |
Output is correct |
16 |
Correct |
138 ms |
300 KB |
Output is correct |
17 |
Correct |
127 ms |
296 KB |
Output is correct |
18 |
Correct |
96 ms |
296 KB |
Output is correct |
19 |
Correct |
113 ms |
300 KB |
Output is correct |
20 |
Correct |
106 ms |
296 KB |
Output is correct |
21 |
Correct |
97 ms |
300 KB |
Output is correct |
22 |
Correct |
100 ms |
300 KB |
Output is correct |
23 |
Correct |
38 ms |
300 KB |
Output is correct |
24 |
Correct |
100 ms |
292 KB |
Output is correct |
25 |
Correct |
80 ms |
308 KB |
Output is correct |
26 |
Correct |
97 ms |
300 KB |
Output is correct |
27 |
Correct |
116 ms |
204 KB |
Output is correct |
28 |
Correct |
138 ms |
204 KB |
Output is correct |
29 |
Correct |
88 ms |
296 KB |
Output is correct |
30 |
Correct |
94 ms |
300 KB |
Output is correct |
31 |
Correct |
139 ms |
296 KB |
Output is correct |
32 |
Correct |
135 ms |
204 KB |
Output is correct |
33 |
Correct |
135 ms |
296 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 |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 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 |
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 |
145 ms |
300 KB |
Output is correct |
15 |
Correct |
147 ms |
304 KB |
Output is correct |
16 |
Correct |
138 ms |
300 KB |
Output is correct |
17 |
Correct |
127 ms |
296 KB |
Output is correct |
18 |
Correct |
96 ms |
296 KB |
Output is correct |
19 |
Correct |
113 ms |
300 KB |
Output is correct |
20 |
Correct |
106 ms |
296 KB |
Output is correct |
21 |
Correct |
97 ms |
300 KB |
Output is correct |
22 |
Correct |
100 ms |
300 KB |
Output is correct |
23 |
Correct |
38 ms |
300 KB |
Output is correct |
24 |
Correct |
100 ms |
292 KB |
Output is correct |
25 |
Correct |
80 ms |
308 KB |
Output is correct |
26 |
Correct |
97 ms |
300 KB |
Output is correct |
27 |
Correct |
116 ms |
204 KB |
Output is correct |
28 |
Correct |
138 ms |
204 KB |
Output is correct |
29 |
Correct |
88 ms |
296 KB |
Output is correct |
30 |
Correct |
94 ms |
300 KB |
Output is correct |
31 |
Correct |
139 ms |
296 KB |
Output is correct |
32 |
Correct |
135 ms |
204 KB |
Output is correct |
33 |
Correct |
135 ms |
296 KB |
Output is correct |
34 |
Execution timed out |
2091 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 |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 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 |
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 |
145 ms |
300 KB |
Output is correct |
15 |
Correct |
147 ms |
304 KB |
Output is correct |
16 |
Correct |
138 ms |
300 KB |
Output is correct |
17 |
Correct |
127 ms |
296 KB |
Output is correct |
18 |
Correct |
96 ms |
296 KB |
Output is correct |
19 |
Correct |
113 ms |
300 KB |
Output is correct |
20 |
Correct |
106 ms |
296 KB |
Output is correct |
21 |
Correct |
97 ms |
300 KB |
Output is correct |
22 |
Correct |
100 ms |
300 KB |
Output is correct |
23 |
Correct |
38 ms |
300 KB |
Output is correct |
24 |
Correct |
100 ms |
292 KB |
Output is correct |
25 |
Correct |
80 ms |
308 KB |
Output is correct |
26 |
Correct |
97 ms |
300 KB |
Output is correct |
27 |
Correct |
116 ms |
204 KB |
Output is correct |
28 |
Correct |
138 ms |
204 KB |
Output is correct |
29 |
Correct |
88 ms |
296 KB |
Output is correct |
30 |
Correct |
94 ms |
300 KB |
Output is correct |
31 |
Correct |
139 ms |
296 KB |
Output is correct |
32 |
Correct |
135 ms |
204 KB |
Output is correct |
33 |
Correct |
135 ms |
296 KB |
Output is correct |
34 |
Execution timed out |
2091 ms |
332 KB |
Time limit exceeded |
35 |
Halted |
0 ms |
0 KB |
- |