#include <bits/stdc++.h>
#define FOR(i,p,k) for(int i=(p);i<=(k);++i)
#define REP(i,n) FOR(i,0,(n)-1)
#define ssize(x) (int(x.size()))
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pii;
int main(){
int n;
scanf("%d\n", &n);
int n2 = n<<1;
vector<int> s(n2);
REP(i, n2){
char c;
scanf("%c", &c);
s[i] = c=='B';
}
int wyn = 0;
REP(xd, n){
vector<pii> prz;
vector<vector<int>> lewo(2), prawo(2);
REP(i, n) lewo[s[i]].emplace_back(i);
FOR(i, n, n2-1) prawo[s[i]].emplace_back(i);
REP(i, ssize(lewo[0])) prz.emplace_back(lewo[0][i], prawo[1][i]);
REP(i, ssize(lewo[1])) prz.emplace_back(lewo[1][i], prawo[0][i]);
int tmp = 0;
REP(i, n) REP(j, i){
pii a = prz[i], b = prz[j];
if(a.se > b.se) swap(a, b);
if(a.fi < b.fi && b.fi < a.se) ++tmp;
}
wyn = max(wyn, tmp);
s.insert(s.begin(), s.back());
s.pop_back();
}
printf("%d", wyn);
return 0;
}
Compilation message
monochrome.cpp: In function 'int main()':
monochrome.cpp:13:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | scanf("%d\n", &n);
| ~~~~~^~~~~~~~~~~~
monochrome.cpp:18:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
18 | scanf("%c", &c);
| ~~~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
17 ms |
344 KB |
Output is correct |
15 |
Correct |
18 ms |
344 KB |
Output is correct |
16 |
Correct |
17 ms |
344 KB |
Output is correct |
17 |
Correct |
17 ms |
344 KB |
Output is correct |
18 |
Correct |
12 ms |
344 KB |
Output is correct |
19 |
Correct |
13 ms |
344 KB |
Output is correct |
20 |
Correct |
14 ms |
344 KB |
Output is correct |
21 |
Correct |
12 ms |
344 KB |
Output is correct |
22 |
Correct |
12 ms |
344 KB |
Output is correct |
23 |
Correct |
5 ms |
344 KB |
Output is correct |
24 |
Correct |
11 ms |
344 KB |
Output is correct |
25 |
Correct |
10 ms |
344 KB |
Output is correct |
26 |
Correct |
12 ms |
344 KB |
Output is correct |
27 |
Correct |
14 ms |
344 KB |
Output is correct |
28 |
Correct |
15 ms |
348 KB |
Output is correct |
29 |
Correct |
12 ms |
344 KB |
Output is correct |
30 |
Correct |
12 ms |
344 KB |
Output is correct |
31 |
Correct |
15 ms |
344 KB |
Output is correct |
32 |
Correct |
16 ms |
344 KB |
Output is correct |
33 |
Correct |
18 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
17 ms |
344 KB |
Output is correct |
15 |
Correct |
18 ms |
344 KB |
Output is correct |
16 |
Correct |
17 ms |
344 KB |
Output is correct |
17 |
Correct |
17 ms |
344 KB |
Output is correct |
18 |
Correct |
12 ms |
344 KB |
Output is correct |
19 |
Correct |
13 ms |
344 KB |
Output is correct |
20 |
Correct |
14 ms |
344 KB |
Output is correct |
21 |
Correct |
12 ms |
344 KB |
Output is correct |
22 |
Correct |
12 ms |
344 KB |
Output is correct |
23 |
Correct |
5 ms |
344 KB |
Output is correct |
24 |
Correct |
11 ms |
344 KB |
Output is correct |
25 |
Correct |
10 ms |
344 KB |
Output is correct |
26 |
Correct |
12 ms |
344 KB |
Output is correct |
27 |
Correct |
14 ms |
344 KB |
Output is correct |
28 |
Correct |
15 ms |
348 KB |
Output is correct |
29 |
Correct |
12 ms |
344 KB |
Output is correct |
30 |
Correct |
12 ms |
344 KB |
Output is correct |
31 |
Correct |
15 ms |
344 KB |
Output is correct |
32 |
Correct |
16 ms |
344 KB |
Output is correct |
33 |
Correct |
18 ms |
344 KB |
Output is correct |
34 |
Execution timed out |
2044 ms |
344 KB |
Time limit exceeded |
35 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
17 ms |
344 KB |
Output is correct |
15 |
Correct |
18 ms |
344 KB |
Output is correct |
16 |
Correct |
17 ms |
344 KB |
Output is correct |
17 |
Correct |
17 ms |
344 KB |
Output is correct |
18 |
Correct |
12 ms |
344 KB |
Output is correct |
19 |
Correct |
13 ms |
344 KB |
Output is correct |
20 |
Correct |
14 ms |
344 KB |
Output is correct |
21 |
Correct |
12 ms |
344 KB |
Output is correct |
22 |
Correct |
12 ms |
344 KB |
Output is correct |
23 |
Correct |
5 ms |
344 KB |
Output is correct |
24 |
Correct |
11 ms |
344 KB |
Output is correct |
25 |
Correct |
10 ms |
344 KB |
Output is correct |
26 |
Correct |
12 ms |
344 KB |
Output is correct |
27 |
Correct |
14 ms |
344 KB |
Output is correct |
28 |
Correct |
15 ms |
348 KB |
Output is correct |
29 |
Correct |
12 ms |
344 KB |
Output is correct |
30 |
Correct |
12 ms |
344 KB |
Output is correct |
31 |
Correct |
15 ms |
344 KB |
Output is correct |
32 |
Correct |
16 ms |
344 KB |
Output is correct |
33 |
Correct |
18 ms |
344 KB |
Output is correct |
34 |
Execution timed out |
2044 ms |
344 KB |
Time limit exceeded |
35 |
Halted |
0 ms |
0 KB |
- |