#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 4e5 + 2;
int n;
string s;
vector<int> white, black;
bool cross(int x1, int y1, int x2, int y2){
if(x1 > y1) swap(x1, y1);
if(x2 > y2) swap(x2, y2);
if(x1 < x2 && y2 < y1) return false;
if(x2 < x1 && y1 < y2) return false;
if(x1 > y2 || x2 > y1) return false;
return true;
}
int calc(int delta){
int ret = 0;
for(int i = 0; i < n; ++i){
for(int j = i + 1; j < n; ++j){
if(cross(white[i], black[(i + delta) % n], white[j], black[(j + delta) % n])) ++ret;
}
}
return ret;
}
int main(){
cin >> n >> s;
for(int i = 0; i < 2*n; ++i){
if(s[i] == 'W') white.push_back(i);
else black.push_back(i);
}
int ans = 0;
for(int i = 0; i < n; ++i){
ans = max(ans, calc(i));
}
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
296 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
300 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
300 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
296 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
300 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
300 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
64 ms |
288 KB |
Output is correct |
15 |
Correct |
63 ms |
296 KB |
Output is correct |
16 |
Correct |
61 ms |
288 KB |
Output is correct |
17 |
Correct |
68 ms |
284 KB |
Output is correct |
18 |
Correct |
49 ms |
284 KB |
Output is correct |
19 |
Correct |
52 ms |
296 KB |
Output is correct |
20 |
Correct |
50 ms |
212 KB |
Output is correct |
21 |
Correct |
43 ms |
284 KB |
Output is correct |
22 |
Correct |
45 ms |
296 KB |
Output is correct |
23 |
Correct |
17 ms |
212 KB |
Output is correct |
24 |
Correct |
42 ms |
212 KB |
Output is correct |
25 |
Correct |
38 ms |
212 KB |
Output is correct |
26 |
Correct |
45 ms |
212 KB |
Output is correct |
27 |
Correct |
52 ms |
296 KB |
Output is correct |
28 |
Correct |
60 ms |
304 KB |
Output is correct |
29 |
Correct |
48 ms |
212 KB |
Output is correct |
30 |
Correct |
45 ms |
212 KB |
Output is correct |
31 |
Correct |
64 ms |
288 KB |
Output is correct |
32 |
Correct |
63 ms |
288 KB |
Output is correct |
33 |
Correct |
63 ms |
288 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
296 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
300 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
300 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
64 ms |
288 KB |
Output is correct |
15 |
Correct |
63 ms |
296 KB |
Output is correct |
16 |
Correct |
61 ms |
288 KB |
Output is correct |
17 |
Correct |
68 ms |
284 KB |
Output is correct |
18 |
Correct |
49 ms |
284 KB |
Output is correct |
19 |
Correct |
52 ms |
296 KB |
Output is correct |
20 |
Correct |
50 ms |
212 KB |
Output is correct |
21 |
Correct |
43 ms |
284 KB |
Output is correct |
22 |
Correct |
45 ms |
296 KB |
Output is correct |
23 |
Correct |
17 ms |
212 KB |
Output is correct |
24 |
Correct |
42 ms |
212 KB |
Output is correct |
25 |
Correct |
38 ms |
212 KB |
Output is correct |
26 |
Correct |
45 ms |
212 KB |
Output is correct |
27 |
Correct |
52 ms |
296 KB |
Output is correct |
28 |
Correct |
60 ms |
304 KB |
Output is correct |
29 |
Correct |
48 ms |
212 KB |
Output is correct |
30 |
Correct |
45 ms |
212 KB |
Output is correct |
31 |
Correct |
64 ms |
288 KB |
Output is correct |
32 |
Correct |
63 ms |
288 KB |
Output is correct |
33 |
Correct |
63 ms |
288 KB |
Output is correct |
34 |
Execution timed out |
2086 ms |
212 KB |
Time limit exceeded |
35 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
296 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
300 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
300 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
64 ms |
288 KB |
Output is correct |
15 |
Correct |
63 ms |
296 KB |
Output is correct |
16 |
Correct |
61 ms |
288 KB |
Output is correct |
17 |
Correct |
68 ms |
284 KB |
Output is correct |
18 |
Correct |
49 ms |
284 KB |
Output is correct |
19 |
Correct |
52 ms |
296 KB |
Output is correct |
20 |
Correct |
50 ms |
212 KB |
Output is correct |
21 |
Correct |
43 ms |
284 KB |
Output is correct |
22 |
Correct |
45 ms |
296 KB |
Output is correct |
23 |
Correct |
17 ms |
212 KB |
Output is correct |
24 |
Correct |
42 ms |
212 KB |
Output is correct |
25 |
Correct |
38 ms |
212 KB |
Output is correct |
26 |
Correct |
45 ms |
212 KB |
Output is correct |
27 |
Correct |
52 ms |
296 KB |
Output is correct |
28 |
Correct |
60 ms |
304 KB |
Output is correct |
29 |
Correct |
48 ms |
212 KB |
Output is correct |
30 |
Correct |
45 ms |
212 KB |
Output is correct |
31 |
Correct |
64 ms |
288 KB |
Output is correct |
32 |
Correct |
63 ms |
288 KB |
Output is correct |
33 |
Correct |
63 ms |
288 KB |
Output is correct |
34 |
Execution timed out |
2086 ms |
212 KB |
Time limit exceeded |
35 |
Halted |
0 ms |
0 KB |
- |