QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#597965 | #6338. Chorus | Dimash# | 16 | 258ms | 5584kb | C++17 | 1.5kb | 2024-09-28 19:42:43 | 2024-09-28 19:42:44 |
Judging History
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 <= n; j++) {
dp[i][j] = inf;
}
for(int j = 1; j <= i; j++) {
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] << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int t = 1;
// cin >> t;
while(t--)
test();
return 0;
}
详细
Subtask #1:
score: 16
Accepted
Test #1:
score: 16
Accepted
time: 0ms
memory: 3668kb
input:
1 1 BA
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 16
Accepted
time: 0ms
memory: 3572kb
input:
7 5 ABBAAABBABABBA
output:
3
result:
ok 1 number(s): "3"
Test #3:
score: 16
Accepted
time: 0ms
memory: 3644kb
input:
10 3 BABBABAABAABBABBBAAA
output:
26
result:
ok 1 number(s): "26"
Test #4:
score: 16
Accepted
time: 0ms
memory: 3636kb
input:
10 2 AAABBABABBAAABBBAABB
output:
11
result:
ok 1 number(s): "11"
Test #5:
score: 16
Accepted
time: 0ms
memory: 3652kb
input:
10 1 BBBBBBBBBBAAAAAAAAAA
output:
100
result:
ok 1 number(s): "100"
Test #6:
score: 16
Accepted
time: 0ms
memory: 3580kb
input:
10 2 BBBBBBBBBBAAAAAAAAAA
output:
75
result:
ok 1 number(s): "75"
Test #7:
score: 16
Accepted
time: 0ms
memory: 3636kb
input:
10 9 BBBBBBBBBBAAAAAAAAAA
output:
56
result:
ok 1 number(s): "56"
Test #8:
score: 16
Accepted
time: 0ms
memory: 3612kb
input:
10 10 BBBBBBBBBBAAAAAAAAAA
output:
55
result:
ok 1 number(s): "55"
Test #9:
score: 16
Accepted
time: 0ms
memory: 3648kb
input:
10 10 ABABABABABABABABABAB
output:
0
result:
ok 1 number(s): "0"
Test #10:
score: 16
Accepted
time: 1ms
memory: 5584kb
input:
10 2 ABAAABABABBBABABABAB
output:
14
result:
ok 1 number(s): "14"
Test #11:
score: 16
Accepted
time: 0ms
memory: 3704kb
input:
10 4 ABAABBAAABBBAAABBBAB
output:
2
result:
ok 1 number(s): "2"
Test #12:
score: 16
Accepted
time: 0ms
memory: 3700kb
input:
10 4 ABAAABBBAAABBBAABBAB
output:
2
result:
ok 1 number(s): "2"
Subtask #2:
score: 0
Time Limit Exceeded
Dependency #1:
100%
Accepted
Test #13:
score: 24
Accepted
time: 258ms
memory: 4388kb
input:
179 54 AAABABABABBAAABBABBABBABBBAAABAAAAABBBABAAAAABABBBAABBBABABBAABABAABABBBBABAABAABABABBBABBAABABBAABBAABABBAAABAAAAAAAABBAAAAABAAABBBBBBBABBAABBBABABAABBAABBABABABBABAAABABAAABABABBAABABAAABBABABABABABBAAABABBBBBBBAABBBAABABBBBABAABBAAAABAABBABABAABAAABABAAAABBBAABAAABBABABBBABAAABAABBBABBBBBA...
output:
41
result:
ok 1 number(s): "41"
Test #14:
score: 0
Time Limit Exceeded
input:
500 93 ABABAABBBBABAABAABAAAAABABBBBBABABBABAAAABAABBBBABAABBBAAABBABABAAAABAABBABAAABBAAABBBABBAAAAAABABABBBABABBBAABAAABAABABAAABAAABBAAABABBBAABBABBBABBBAABAAAABBBAABBBABAAAAAABABABBBABAAAABBBBBAABBBABAAABAABBBABABAABABBBBABBABBBBBBBABAAAABAABAABBABBBAABBBAAAAAAABBAABAAABBBABBBAAABABBBBAABBBABABB...
output:
result:
Subtask #3:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%
Subtask #5:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%