QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#598009 | #6338. Chorus | Dimash# | 40 | 5ms | 11652kb | C++17 | 2.0kb | 2024-09-28 19:59:46 | 2024-09-28 19:59:47 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e3 + 12, MOD = (int)1e9 + 7;
int n, k, dp[N][N], c[N][N], f[N], pref[N], opt[N][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++) {
if(y[i] > x[r]) continue;
int t_ =0 ;
t_ += pref[x[r]];
if(y[i]> 0) t_ -= pref[y[i] - 1];
ret += t_;
}
return ret;
};
for(int i = 1; i <= n; i++) {
for(int j = i; j >= 1; j--) {
c[j][i] = c[j + 1][i];
if(y[j] <= x[i]) {
c[j][i] += pref[x[i]];
if(y[j]) c[j][i] -= pref[y[j] - 1];
}
}
}
}
int cost(int l, int r) {
return c[l][r];
}
void calc(int l, int r, int lv, int _l, int _r) {
if(l > r) return;
int t = (l + r) >> 1, opt;
for(int i = _l; i <= min(t, _r); i++) {
int u = dp[i - 1][lv - 1] + cost(i, t);
if(u < dp[t][lv]) {
opt = i;
dp[t][lv] = u;
}
}
calc(l, t - 1, lv, _l, opt);
calc(t + 1, r, lv, opt, _r);
}
void test() {
cin >> n >> k >> s;
x.push_back(0);
y.push_back(0);
for(int i = 0; i < n + n; i++) {
pref[i] = (s[i] == 'A');
if(i > 0) pref[i] += pref[i - 1];
if(s[i] == 'A') {
x.push_back(i);
} else {
y.push_back(i);
}
}
prec();
for(int i = 1; i <= n; i++) {
for(int j = 0; j <= n; j++) {
dp[i][j] = inf;
}
}
for(int i = 1; i <= n; i++) {
dp[i][1] = cost(1, i);
}
for(int i = 2; i <= k; i++) {
calc(i, n, i, 1, 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: 1ms
memory: 7680kb
input:
1 1 BA
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 16
Accepted
time: 1ms
memory: 7680kb
input:
7 5 ABBAAABBABABBA
output:
3
result:
ok 1 number(s): "3"
Test #3:
score: 16
Accepted
time: 1ms
memory: 7680kb
input:
10 3 BABBABAABAABBABBBAAA
output:
26
result:
ok 1 number(s): "26"
Test #4:
score: 16
Accepted
time: 1ms
memory: 7668kb
input:
10 2 AAABBABABBAAABBBAABB
output:
11
result:
ok 1 number(s): "11"
Test #5:
score: 16
Accepted
time: 1ms
memory: 7752kb
input:
10 1 BBBBBBBBBBAAAAAAAAAA
output:
100
result:
ok 1 number(s): "100"
Test #6:
score: 16
Accepted
time: 1ms
memory: 7756kb
input:
10 2 BBBBBBBBBBAAAAAAAAAA
output:
75
result:
ok 1 number(s): "75"
Test #7:
score: 16
Accepted
time: 1ms
memory: 7760kb
input:
10 9 BBBBBBBBBBAAAAAAAAAA
output:
56
result:
ok 1 number(s): "56"
Test #8:
score: 16
Accepted
time: 1ms
memory: 7740kb
input:
10 10 BBBBBBBBBBAAAAAAAAAA
output:
55
result:
ok 1 number(s): "55"
Test #9:
score: 16
Accepted
time: 1ms
memory: 7676kb
input:
10 10 ABABABABABABABABABAB
output:
0
result:
ok 1 number(s): "0"
Test #10:
score: 16
Accepted
time: 1ms
memory: 7688kb
input:
10 2 ABAAABABABBBABABABAB
output:
14
result:
ok 1 number(s): "14"
Test #11:
score: 16
Accepted
time: 1ms
memory: 7668kb
input:
10 4 ABAABBAAABBBAAABBBAB
output:
2
result:
ok 1 number(s): "2"
Test #12:
score: 16
Accepted
time: 1ms
memory: 7672kb
input:
10 4 ABAAABBBAAABBBAABBAB
output:
2
result:
ok 1 number(s): "2"
Subtask #2:
score: 24
Accepted
Dependency #1:
100%
Accepted
Test #13:
score: 24
Accepted
time: 1ms
memory: 7748kb
input:
179 54 AAABABABABBAAABBABBABBABBBAAABAAAAABBBABAAAAABABBBAABBBABABBAABABAABABBBBABAABAABABABBBABBAABABBAABBAABABBAAABAAAAAAAABBAAAAABAAABBBBBBBABBAABBBABABAABBAABBABABABBABAAABABAAABABABBAABABAAABBABABABABABBAAABABBBBBBBAABBBAABABBBBABAABBAAAABAABBABABAABAAABABAAAABBBAABAAABBABABBBABAAABAABBBABBBBBA...
output:
41
result:
ok 1 number(s): "41"
Test #14:
score: 24
Accepted
time: 0ms
memory: 11524kb
input:
500 93 ABABAABBBBABAABAABAAAAABABBBBBABABBABAAAABAABBBBABAABBBAAABBABABAAAABAABBABAAABBAAABBBABBAAAAAABABABBBABABBBAABAAABAABABAAABAAABBAAABABBBAABBABBBABBBAABAAAABBBAABBBABAAAAAABABABBBABAAAABBBBBAABBBABAAABAABBBABABAABABBBBABBABBBBBBBABAAAABAABAABBABBBAABBBAAAAAAABBAABAAABBBABBBAAABABBBBAABBBABABB...
output:
235
result:
ok 1 number(s): "235"
Test #15:
score: 24
Accepted
time: 5ms
memory: 11652kb
input:
500 273 AAABBABAABAAABABAABBBABAAAABBAAABBABAAABBABABAAAABBBAAABBBAABAABAABBABABABABBAAABBBBBBBAABABBAABABBBAABBBBAAABAAAABABBABBBBBAABAABABAAAABBABABABAAAABBBAAAAABABBAABABABAAABBABAAAABABBBAAABABAABBAABBBAABAABBBAABABBBBABAAABAABBBBABBABAAABABBAABABBABBBBBBBABAABAAAABABABAAABABABABAABBAABBBABBBAAB...
output:
0
result:
ok 1 number(s): "0"
Test #16:
score: 24
Accepted
time: 2ms
memory: 11564kb
input:
500 1 BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...
output:
250000
result:
ok 1 number(s): "250000"
Test #17:
score: 24
Accepted
time: 2ms
memory: 10744kb
input:
500 2 BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...
output:
187500
result:
ok 1 number(s): "187500"
Test #18:
score: 24
Accepted
time: 0ms
memory: 11320kb
input:
500 499 BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...
output:
125251
result:
ok 1 number(s): "125251"
Test #19:
score: 24
Accepted
time: 2ms
memory: 11488kb
input:
500 500 BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...
output:
125250
result:
ok 1 number(s): "125250"
Test #20:
score: 24
Accepted
time: 3ms
memory: 11528kb
input:
500 10 ABAAABBBAABBABABAABAABABBBAABABABBAABABAABAABABABBBBABAABBAAAAAAABAABAABAABBABBABABBBABABBAABABBBBAABBBBABAAAAAAABAABAAABABABBAABABBABBAAAABAABBBAABABBABABBBBAAAABABBAAAAABAABBBBBBBBABBABBBAABBABBAAAABAABBBBBBAABBBAAAABABBAAABAABAABBBBAABBAAABBAABBAAAAABAAAAAABBAABABBABABBBABAAABBBAAABABAAABB...
output:
9129
result:
ok 1 number(s): "9129"
Test #21:
score: 24
Accepted
time: 5ms
memory: 11500kb
input:
500 500 ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB...
output:
0
result:
ok 1 number(s): "0"
Test #22:
score: 24
Accepted
time: 4ms
memory: 7856kb
input:
500 416 ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB...
output:
84
result:
ok 1 number(s): "84"
Test #23:
score: 24
Accepted
time: 3ms
memory: 10580kb
input:
499 167 ABAABBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAAB...
output:
2
result:
ok 1 number(s): "2"
Test #24:
score: 24
Accepted
time: 3ms
memory: 10948kb
input:
499 167 ABAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAA...
output:
2
result:
ok 1 number(s): "2"
Subtask #3:
score: 0
Runtime Error
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Test #25:
score: 0
Runtime Error
input:
4918 2048 ABBBBBBAAAAABBBBAAAABBABBAAAABBBAABBBABABBAAAABBBAAAABAABBAAABAAABAABBAAABAAABBBAABBBBBBABAABBBBAAAAABBBBBABBBABABBBBBABAAAAAABAABBABBABBBBBAABAABAAAAAABBBBBAABBBABBBAAABBABBABBBAABBBBBBABBBABAABABABABABAAABBABABBAABAABBBBABABBAABABABABBAABABABBABABABAAABABBBABBBABBABBBBAAAABBBBAAABBBABBBA...
output:
result:
Subtask #4:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
0%
Subtask #5:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
0%