// #pragma GCC optimize("O3,Ofast,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define MP make_pair
#define pb push_back
#define REP(i,n) for(int i = 0; (i) < (n); (i)++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
void fastio() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
const double EPS = 0.00001;
const int INF = 1e9+500;
const int N = 3e5+5;
const int ALPH = 26;
const int LGN = 25;
constexpr int MOD = 1e9+7;
int n,m,q;
vector<int> b, w;
int counter() {
int cnt = 0;
for(int i = 0; i < n; i++) {
for(int j = i + 1; j < n; j++) {
int a1= b[i], a2 = b[j], b1 = w[i], b2 = w[j];
if(a1 > b1) swap(a1, b1);
if(a2 > b2) swap(a2, b2);
if((a1 < a2 && a2 < b1) != (a1 < b2 && a2 < b2)) {
cnt++;
}
}
}
return cnt;
}
inline void solve() {
cin>>n;
string s;
cin >> s;
for(int i = 0; i<2*n; i++) {
auto c = s[i];
if(c == 'B') b.pb(i);
else w.pb(i);
}
int ans = 0;
do
{
ans = max(ans, counter());
} while (next_permutation(all(w)));
cout << ans << "\n";
}
signed main() {
//fastio();
int test = 1;
//cin>>test;
while(test--) {
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |