This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
____ ____ ____ ____ ____ ____
||l |||e |||i |||n |||a |||d ||
||__|||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|/__\|
**/
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
int n, k;
string s;
int check(int mask)
{
int cnt0 = 0, cnt1 = 0, ans = 0;
/**for (int i = 0; i < 2 * n; i ++)
{
if ((mask & (1 << i)) > 0)
cout << 1;
else
cout << 0;
}
cout << endl;*/
for (int i = 0; i < 2 * n; i ++)
{
int cur = 0;
if ((mask & (1 << i)) > 0)
cur ++;
///cout << i << " : " << cnt0 << " : " << cnt1 << endl;
if (cur == 0)
{
cnt0 ++;
continue;
}
if (cnt1 > 0)
cnt1 --;
else
{
if (cnt0 == 0)
return 2 * n + 1;
cnt1 = cnt0 - 1;
cnt0 = 0;
ans ++;
}
}
return ans;
}
void solve()
{
cin >> n >> k >> s;
/**int ms = 0;
for (int i = 0; i < 2 * n; i ++)
if (s[i] == 'B')
ms = (ms | (1 << i));
cout << ms << " : " << check(ms) << endl;
for (int j = 0; j < 2 * n; j ++)
cout << ((ms & (1 << j)) > 0);
cout << endl;
return;*/
int ans = n * n;
for (int mask = 0; mask <= (1 << (2 * n)); mask ++)
{
int cnt = 0;
for (int i = 0; i < 2 * n; i ++)
{
if ((mask & (1 << i)) > 0)
cnt ++;
}
if (cnt != n)
continue;
int cur = 0, pt = 0;
for (int i = 0; i < 2 * n; i ++)
{
if (s[i] == 'B')
continue;
while((mask & (1 << pt)) > 0)
pt ++;
///cout << i << " : " << pt << endl;
cur = cur + abs(i - pt);
pt ++;
}
/**for (int j = 0; j < 2 * n; j ++)
cout << ((mask & (1 << j)) > 0);
cout << endl;*/
///if (check(mask) == 0)
///cout << mask << endl;
///cout << mask << " : " << check(mask) << " " << cur << endl;
if (check(mask) <= k)
{
//if (cur == 0)
// cout << "!!! " << mask << endl;
///cout << mask << endl;
ans = min(ans, cur);
///cout << ans << endl;
}
}
cout << ans << endl;
}
int main()
{
solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |