# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
789195 |
2023-07-21T07:22:29 Z |
이동현(#10044) |
Chorus (JOI23_chorus) |
C++17 |
|
7 ms |
340 KB |
#include <bits/stdc++.h>
#define mi(x, y) (x = min(x, y))
#define ma(x, y) (x = max(x, y))
using namespace std;
int n, k;
string s;
int dp[1004][504], ndp[1004][504];
int apos[504], an;
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> k;
cin >> s;
for(int i = 0; i < n * 2; ++i){
if(s[i] == 'A'){
apos[an++] = i;
}
}
int ans = (int)1e9;
for(int i = 0; i < (1 << (n * 2)); ++i){
if(__builtin_popcount(i) != n){
continue;
}
int cost = 0, ccnt = 0;
int h = 0, ok = 0, kcnt = 0, dec = 0;
for(int j = 0; j < n * 2; ++j){
if(i & (1 << j)){
cost += abs(apos[ccnt++] - j);
h += 1;
if(!dec) ok += 1;
}
else{
h -= 1;
if(h < 0){
cost = (int)1e9;
break;
}
ok -= 1;
dec = 1;
if(!ok){
++kcnt;
dec = 0;
ok = h;
}
}
}
if(kcnt <= k) ans = min(ans, cost);
}
cout << ans << '\n';
// dp[0][0] = 0;
// for(int i = 0; i < n * 2; ++i){
// for(int j = 0; j <= i; ++j){
// for(int k = 0; k <= i; ++k){
// if(dp[j][k] == (int)1e9) continue;
// int acnt = i - (i - j) / 2;
// int istr = (k == i);
// if(dp[j][k] + abs(apos[acnt] - i) < ndp[j + 1][k + istr]){
// ndp[j + 1][k + istr] = dp[j][k] + abs(apos[acnt] - i);
// }
// if(j){
// int nk = (k ? k - 1 : j);
// if(dp[j][k] < ndp[j - 1][nk]){
// ndp[j - 1][nk] = dp[j][k];
// }
// }
// }
// }
// }
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
6 ms |
324 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
6 ms |
212 KB |
Output is correct |
8 |
Correct |
6 ms |
212 KB |
Output is correct |
9 |
Correct |
6 ms |
212 KB |
Output is correct |
10 |
Correct |
5 ms |
340 KB |
Output is correct |
11 |
Correct |
7 ms |
212 KB |
Output is correct |
12 |
Correct |
6 ms |
212 KB |
Output is correct |
13 |
Correct |
7 ms |
212 KB |
Output is correct |
14 |
Correct |
5 ms |
324 KB |
Output is correct |
15 |
Correct |
6 ms |
328 KB |
Output is correct |
16 |
Correct |
6 ms |
328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
6 ms |
324 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
6 ms |
212 KB |
Output is correct |
8 |
Correct |
6 ms |
212 KB |
Output is correct |
9 |
Correct |
6 ms |
212 KB |
Output is correct |
10 |
Correct |
5 ms |
340 KB |
Output is correct |
11 |
Correct |
7 ms |
212 KB |
Output is correct |
12 |
Correct |
6 ms |
212 KB |
Output is correct |
13 |
Correct |
7 ms |
212 KB |
Output is correct |
14 |
Correct |
5 ms |
324 KB |
Output is correct |
15 |
Correct |
6 ms |
328 KB |
Output is correct |
16 |
Correct |
6 ms |
328 KB |
Output is correct |
17 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
6 ms |
324 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
6 ms |
212 KB |
Output is correct |
8 |
Correct |
6 ms |
212 KB |
Output is correct |
9 |
Correct |
6 ms |
212 KB |
Output is correct |
10 |
Correct |
5 ms |
340 KB |
Output is correct |
11 |
Correct |
7 ms |
212 KB |
Output is correct |
12 |
Correct |
6 ms |
212 KB |
Output is correct |
13 |
Correct |
7 ms |
212 KB |
Output is correct |
14 |
Correct |
5 ms |
324 KB |
Output is correct |
15 |
Correct |
6 ms |
328 KB |
Output is correct |
16 |
Correct |
6 ms |
328 KB |
Output is correct |
17 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
6 ms |
324 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
6 ms |
212 KB |
Output is correct |
8 |
Correct |
6 ms |
212 KB |
Output is correct |
9 |
Correct |
6 ms |
212 KB |
Output is correct |
10 |
Correct |
5 ms |
340 KB |
Output is correct |
11 |
Correct |
7 ms |
212 KB |
Output is correct |
12 |
Correct |
6 ms |
212 KB |
Output is correct |
13 |
Correct |
7 ms |
212 KB |
Output is correct |
14 |
Correct |
5 ms |
324 KB |
Output is correct |
15 |
Correct |
6 ms |
328 KB |
Output is correct |
16 |
Correct |
6 ms |
328 KB |
Output is correct |
17 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
6 ms |
324 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
6 ms |
212 KB |
Output is correct |
8 |
Correct |
6 ms |
212 KB |
Output is correct |
9 |
Correct |
6 ms |
212 KB |
Output is correct |
10 |
Correct |
5 ms |
340 KB |
Output is correct |
11 |
Correct |
7 ms |
212 KB |
Output is correct |
12 |
Correct |
6 ms |
212 KB |
Output is correct |
13 |
Correct |
7 ms |
212 KB |
Output is correct |
14 |
Correct |
5 ms |
324 KB |
Output is correct |
15 |
Correct |
6 ms |
328 KB |
Output is correct |
16 |
Correct |
6 ms |
328 KB |
Output is correct |
17 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |