#include <bits/stdc++.h>
#define fi first
#define se second
#define ssize(x) int(x.size())
#define pn printf("\n");
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vv vector
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int inf = 2e09; ll infll = 2e18; int mod = 119<<23|1;
void answer(){
int n; scanf("%d", &n);
char c = char(getchar_unlocked());
vector<int> t(n<<1), pos_w(n), pos_b(n);
int w_cnt = 0, b_cnt = 0;
for(int i = 0; i < n<<1; ++i){
c = char(getchar_unlocked()), t[i] = c == 'B' ? 1 : 0;
if(c == 'W') pos_w[w_cnt++] = i;
else pos_b[b_cnt++] = i;
}
ll result = 0;
vector<int> dp(n<<1, 0), is_start(n<<1, -1);
for(int offset = 0; offset < n; ++offset){
ll res_local = 0;
for(int i = 0; i < n; ++i) is_start[min(pos_b[i], pos_w[(i+offset)%n])] = max(pos_b[i], pos_w[(i+offset)%n]);
//~ printf("%d %d\n", min(pos_b[i], pos_w[(i+offset)%n]), max(pos_b[i], pos_w[(i+offset)%n]));
for(int i = 0; i < n<<1; ++i){
if(is_start[i] != -1){
res_local += dp[is_start[i]];
for(int j = is_start[i]; j < n<<1; ++j) ++dp[j];
}
else for(int j = i; j < n<<1; ++j) --dp[j];
}
result = max(result, res_local);
//~ printf("%lld\n", res_local);
fill(all(dp), 0), fill(all(is_start), -1);
}
printf("%lld\n", result);
}
int main(){
int T = 1;
for(++T; --T; ) answer();
return 0;
}
Compilation message
monochrome.cpp: In function 'void answer()':
monochrome.cpp:14:15: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | int n; scanf("%d", &n);
| ~~~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
436 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
436 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
23 ms |
348 KB |
Output is correct |
15 |
Correct |
22 ms |
344 KB |
Output is correct |
16 |
Correct |
22 ms |
432 KB |
Output is correct |
17 |
Correct |
24 ms |
440 KB |
Output is correct |
18 |
Correct |
15 ms |
348 KB |
Output is correct |
19 |
Correct |
17 ms |
444 KB |
Output is correct |
20 |
Correct |
19 ms |
600 KB |
Output is correct |
21 |
Correct |
16 ms |
348 KB |
Output is correct |
22 |
Correct |
16 ms |
348 KB |
Output is correct |
23 |
Correct |
6 ms |
348 KB |
Output is correct |
24 |
Correct |
13 ms |
348 KB |
Output is correct |
25 |
Correct |
14 ms |
344 KB |
Output is correct |
26 |
Correct |
13 ms |
440 KB |
Output is correct |
27 |
Correct |
14 ms |
348 KB |
Output is correct |
28 |
Correct |
17 ms |
348 KB |
Output is correct |
29 |
Correct |
14 ms |
348 KB |
Output is correct |
30 |
Correct |
17 ms |
444 KB |
Output is correct |
31 |
Correct |
19 ms |
444 KB |
Output is correct |
32 |
Correct |
17 ms |
440 KB |
Output is correct |
33 |
Correct |
22 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
436 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
23 ms |
348 KB |
Output is correct |
15 |
Correct |
22 ms |
344 KB |
Output is correct |
16 |
Correct |
22 ms |
432 KB |
Output is correct |
17 |
Correct |
24 ms |
440 KB |
Output is correct |
18 |
Correct |
15 ms |
348 KB |
Output is correct |
19 |
Correct |
17 ms |
444 KB |
Output is correct |
20 |
Correct |
19 ms |
600 KB |
Output is correct |
21 |
Correct |
16 ms |
348 KB |
Output is correct |
22 |
Correct |
16 ms |
348 KB |
Output is correct |
23 |
Correct |
6 ms |
348 KB |
Output is correct |
24 |
Correct |
13 ms |
348 KB |
Output is correct |
25 |
Correct |
14 ms |
344 KB |
Output is correct |
26 |
Correct |
13 ms |
440 KB |
Output is correct |
27 |
Correct |
14 ms |
348 KB |
Output is correct |
28 |
Correct |
17 ms |
348 KB |
Output is correct |
29 |
Correct |
14 ms |
348 KB |
Output is correct |
30 |
Correct |
17 ms |
444 KB |
Output is correct |
31 |
Correct |
19 ms |
444 KB |
Output is correct |
32 |
Correct |
17 ms |
440 KB |
Output is correct |
33 |
Correct |
22 ms |
344 KB |
Output is correct |
34 |
Execution timed out |
2064 ms |
344 KB |
Time limit exceeded |
35 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
436 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
23 ms |
348 KB |
Output is correct |
15 |
Correct |
22 ms |
344 KB |
Output is correct |
16 |
Correct |
22 ms |
432 KB |
Output is correct |
17 |
Correct |
24 ms |
440 KB |
Output is correct |
18 |
Correct |
15 ms |
348 KB |
Output is correct |
19 |
Correct |
17 ms |
444 KB |
Output is correct |
20 |
Correct |
19 ms |
600 KB |
Output is correct |
21 |
Correct |
16 ms |
348 KB |
Output is correct |
22 |
Correct |
16 ms |
348 KB |
Output is correct |
23 |
Correct |
6 ms |
348 KB |
Output is correct |
24 |
Correct |
13 ms |
348 KB |
Output is correct |
25 |
Correct |
14 ms |
344 KB |
Output is correct |
26 |
Correct |
13 ms |
440 KB |
Output is correct |
27 |
Correct |
14 ms |
348 KB |
Output is correct |
28 |
Correct |
17 ms |
348 KB |
Output is correct |
29 |
Correct |
14 ms |
348 KB |
Output is correct |
30 |
Correct |
17 ms |
444 KB |
Output is correct |
31 |
Correct |
19 ms |
444 KB |
Output is correct |
32 |
Correct |
17 ms |
440 KB |
Output is correct |
33 |
Correct |
22 ms |
344 KB |
Output is correct |
34 |
Execution timed out |
2064 ms |
344 KB |
Time limit exceeded |
35 |
Halted |
0 ms |
0 KB |
- |