QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#599187 | #6338. Chorus | Dimash | 0 | 0ms | 3716kb | C++23 | 1.8kb | 2024-09-29 02:02:07 | 2024-09-29 02:02:08 |
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 5e3 + 12, MOD = (int)1e9 + 7;
int n, k, x[N], y[N], pref[ 2 * N], col[N], opt[N];
ll dp[N], c[N][N];
void prec() {
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]] - pref[y[j] - 1];;
}
}
}
}
pair<ll, ll> calc(ll pen) {
int it = 1;
for(int i = 1; i <= n; i++) {
// it = 1;
dp[i] = dp[it - 1] + c[it][i] - pen;
col[i] = col[it - 1] + 1;
while(it + 1 <= i && make_pair(dp[it] + c[it + 1][i] - pen, (col[it] + 1)) < make_pair(dp[i], col[i])) {
it++;
}
// cout << i << ' ' << it << '\n';
dp[i] = dp[it - 1] + c[it][i] - pen;
col[i] = col[it - 1] + 1;
}
// cout << "________________\n";
return {dp[n], col[n]};
}
void test() {
cin >> n >> k;
int _x = 0, _y = 0;
for(int i = 1; i <= n + n; i++) {
char a;
cin >> a;
pref[i] = pref[i - 1];
if(a == 'A') {
x[++_x] = i;
pref[i]++;
} else {
y[++_y] = i;
}
}
prec();
ll l = -1e12, r = 1e12, res;
while(r - l > 1) {
ll mid = (l + r) / 2;
auto [val, t] = calc(mid);
// cout << mid << ' ' << val << ' ' << t << '\n';
if(t > k) {
r = mid;
} else {
l = mid;
res = val + k * 1ll * mid;
}
}
cout << res << '\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: 0
Wrong Answer
Test #1:
score: 16
Accepted
time: 0ms
memory: 3648kb
input:
1 1 BA
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Wrong Answer
time: 0ms
memory: 3716kb
input:
7 5 ABBAAABBABABBA
output:
4
result:
wrong answer 1st numbers differ - expected: '3', found: '4'
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%