QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#597954 | #6338. Chorus | Dimash# | 0 | 0ms | 3756kb | C++17 | 1.5kb | 2024-09-28 19:36:29 | 2024-09-28 19:36:33 |
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 5e2 + 12, MOD = (int)1e9 + 7;
int n, k, dp[N][N], c[N][N], f[N];
string s;
vector<int> x, y;
const int inf = 1e9;
void prec() {
auto get = [&](int l, int r) {
int ret =0;
for(int i = l; i <= r; i++) {
for(int f = 1; f <= n + n; f++) {
if(s[f] == 'A' && f >= y[i] && f <= x[r]) {
ret++;
}
}
}
return ret;
};
for(int i = 1; i <= n; i++) {
for(int j = i; j >= 1; j--) {
c[j][i] = get(j, i);
}
}
}
int cost(int l, int r) {
return c[l][r];
}
void test() {
cin >> n >> k >> s;
x.push_back(0);
y.push_back(0);
for(int i = 0; i < n + n; i++) {
if(s[i] == 'A') {
x.push_back(i);
} else {
y.push_back(i);
}
}
prec();
for(int i = 1;i <= n; i++) {
dp[i][0] = inf;
for(int j = 1; j <= i; j++) {
dp[i][j] = inf;
for(int l = i; l >= 1; l--) {
dp[i][j] = min(dp[i][j], dp[l - 1][j - 1] + cost(l, i));
}
// cout << dp[i][j] << ' ';
}
// cout << '\n';
}
cout << dp[n][k];
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int t = 1;
// cin >> t;
while(t--)
test();
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 16
Accepted
time: 0ms
memory: 3596kb
input:
1 1 BA
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 16
Accepted
time: 0ms
memory: 3756kb
input:
7 5 ABBAAABBABABBA
output:
3
result:
ok 1 number(s): "3"
Test #3:
score: 16
Accepted
time: 0ms
memory: 3636kb
input:
10 3 BABBABAABAABBABBBAAA
output:
26
result:
ok 1 number(s): "26"
Test #4:
score: 16
Accepted
time: 0ms
memory: 3696kb
input:
10 2 AAABBABABBAAABBBAABB
output:
11
result:
ok 1 number(s): "11"
Test #5:
score: 16
Accepted
time: 0ms
memory: 3684kb
input:
10 1 BBBBBBBBBBAAAAAAAAAA
output:
100
result:
ok 1 number(s): "100"
Test #6:
score: 16
Accepted
time: 0ms
memory: 3680kb
input:
10 2 BBBBBBBBBBAAAAAAAAAA
output:
75
result:
ok 1 number(s): "75"
Test #7:
score: 0
Wrong Answer
time: 0ms
memory: 3712kb
input:
10 9 BBBBBBBBBBAAAAAAAAAA
output:
30
result:
wrong answer 1st numbers differ - expected: '56', found: '30'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 0
Skipped
Dependency #1:
0%