/**
____ ____ ____ ____ ____ ____
||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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
30 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
31 ms |
344 KB |
Output is correct |
8 |
Correct |
31 ms |
344 KB |
Output is correct |
9 |
Correct |
31 ms |
348 KB |
Output is correct |
10 |
Correct |
34 ms |
344 KB |
Output is correct |
11 |
Correct |
31 ms |
344 KB |
Output is correct |
12 |
Correct |
32 ms |
344 KB |
Output is correct |
13 |
Correct |
31 ms |
360 KB |
Output is correct |
14 |
Correct |
31 ms |
344 KB |
Output is correct |
15 |
Correct |
31 ms |
344 KB |
Output is correct |
16 |
Correct |
30 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
30 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
31 ms |
344 KB |
Output is correct |
8 |
Correct |
31 ms |
344 KB |
Output is correct |
9 |
Correct |
31 ms |
348 KB |
Output is correct |
10 |
Correct |
34 ms |
344 KB |
Output is correct |
11 |
Correct |
31 ms |
344 KB |
Output is correct |
12 |
Correct |
32 ms |
344 KB |
Output is correct |
13 |
Correct |
31 ms |
360 KB |
Output is correct |
14 |
Correct |
31 ms |
344 KB |
Output is correct |
15 |
Correct |
31 ms |
344 KB |
Output is correct |
16 |
Correct |
30 ms |
344 KB |
Output is correct |
17 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
30 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
31 ms |
344 KB |
Output is correct |
8 |
Correct |
31 ms |
344 KB |
Output is correct |
9 |
Correct |
31 ms |
348 KB |
Output is correct |
10 |
Correct |
34 ms |
344 KB |
Output is correct |
11 |
Correct |
31 ms |
344 KB |
Output is correct |
12 |
Correct |
32 ms |
344 KB |
Output is correct |
13 |
Correct |
31 ms |
360 KB |
Output is correct |
14 |
Correct |
31 ms |
344 KB |
Output is correct |
15 |
Correct |
31 ms |
344 KB |
Output is correct |
16 |
Correct |
30 ms |
344 KB |
Output is correct |
17 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
30 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
31 ms |
344 KB |
Output is correct |
8 |
Correct |
31 ms |
344 KB |
Output is correct |
9 |
Correct |
31 ms |
348 KB |
Output is correct |
10 |
Correct |
34 ms |
344 KB |
Output is correct |
11 |
Correct |
31 ms |
344 KB |
Output is correct |
12 |
Correct |
32 ms |
344 KB |
Output is correct |
13 |
Correct |
31 ms |
360 KB |
Output is correct |
14 |
Correct |
31 ms |
344 KB |
Output is correct |
15 |
Correct |
31 ms |
344 KB |
Output is correct |
16 |
Correct |
30 ms |
344 KB |
Output is correct |
17 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
30 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
31 ms |
344 KB |
Output is correct |
8 |
Correct |
31 ms |
344 KB |
Output is correct |
9 |
Correct |
31 ms |
348 KB |
Output is correct |
10 |
Correct |
34 ms |
344 KB |
Output is correct |
11 |
Correct |
31 ms |
344 KB |
Output is correct |
12 |
Correct |
32 ms |
344 KB |
Output is correct |
13 |
Correct |
31 ms |
360 KB |
Output is correct |
14 |
Correct |
31 ms |
344 KB |
Output is correct |
15 |
Correct |
31 ms |
344 KB |
Output is correct |
16 |
Correct |
30 ms |
344 KB |
Output is correct |
17 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |