QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#454443 | #6338. Chorus | snpmrnhlol | 40 | 472ms | 11952kb | C++14 | 2.9kb | 2024-06-24 21:50:23 | 2024-06-24 21:50:26 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 1e6;
const ll inf = 1e18;
char v[N*2];
ll v2[N],v3[N];
ll ps[N + 1];
pair<ll,ll> dp[N + 1];
ll n,k;
ll cnt = 0,cnt2 = 0;
struct line{
ll k,b,id;
};
bool check(line a,line b,line c){
if((a.b - b.b)*(b.k - c.k) == (b.b - c.b)*(a.k - b.k)){
return 1;
}
return (a.b - b.b)*(b.k - c.k) <= (b.b - c.b)*(a.k - b.k);
}
struct CHT{
vector <line> cht;
ll sz = 0, pt = 0;
void init(){
cht.clear();
sz = 0;
pt = 0;
}
void add(ll k,ll b,ll id){
while(sz >= 2 && check(cht[sz - 2],cht[sz - 1],{k,b,id})){
cht.pop_back();
sz--;
}
cht.push_back({k,b,id});
sz++;
}
pair<ll,ll> get(ll x){
assert(sz != 0);
pt = min(pt,sz - 1);
while(pt < sz - 1 && x > -(cht[pt].b - cht[pt + 1].b)/(cht[pt].k - cht[pt + 1].k)){
pt++;
}
return {cht[pt].k*x + cht[pt].b,cht[pt].id};
}
};
CHT cht;
pair <ll,ll> check(ll x){
//cout<<"checking:"<<x<<'\n';
dp[0] = {0,0};
cht.init();
ll pt = 0;
for(ll i = 1;i <= n;i++){
dp[i] = {inf,0};
for(ll j = i - 1;j >= 0;j--){
ll v2j = max(v2[j],j);
if(v2j >= i){
dp[i] = min(dp[i],{dp[j].first + x,dp[j].second + 1});
//cout<<i<<"->"<<j<<' '<<dp[j].first + x<<' '<<dp[j].second + 1<<'\n';
}/*else{
dp[i] = min(dp[i],{dp[j].first + x + (i - v2j)*(n - j) - (ps[i] - ps[v2j]),dp[j].second + 1});
//cout<<i<<"->"<<j<<' '<<dp[j].first<<' '<<x<<' '<<(i - v2[j])*(n - j)<<' '<<(ps[i] - ps[v2[j]])<<' '<<dp[j].second + 1<<'\n';
}*/
}
while(pt < n && max(v2[pt],pt) < i){
ll v2pt = max(v2[pt],pt);
cht.add(-pt,dp[pt].first + x - v2pt*(n - pt) + ps[v2pt],dp[pt].second);
pt++;
}
if(cht.sz != 0){
auto id = cht.get(i);
dp[i] = min(dp[i],{id.first + i*n - ps[i],id.second + 1});
}
//cout<<dp[i].first<<' '<<dp[i].second<<' '<<x<<' '<<i<<'\n';
}
return dp[n];
//cout<<'\n';
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>n>>k;
for(ll i = 0;i < 2*n;i++){
cin>>v[i];
if(v[i] == 'B'){
v2[cnt] = i - cnt;
cnt++;
}
if(v[i] == 'A'){
v3[cnt2] = i - cnt2;
cnt2++;
}
}
for(ll i = 1;i <= n;i++){
ps[i] = ps[i - 1] + (n - v3[i - 1]);
}
ll l = 0,r = inf;
ll ans = 0;
while(l != r){
ll mij = (l + r)/2;
auto x = check(mij);
if(x.second >= k){
l = mij + 1;
}else{
r = mij;
}
}
check(l);
ans = dp[n].first - k*l;
cout<<ans;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 16
Accepted
Test #1:
score: 16
Accepted
time: 1ms
memory: 9808kb
input:
1 1 BA
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 0ms
memory: 9740kb
input:
7 5 ABBAAABBABABBA
output:
3
result:
ok 1 number(s): "3"
Test #3:
score: 0
Accepted
time: 0ms
memory: 9744kb
input:
10 3 BABBABAABAABBABBBAAA
output:
26
result:
ok 1 number(s): "26"
Test #4:
score: 0
Accepted
time: 1ms
memory: 9804kb
input:
10 2 AAABBABABBAAABBBAABB
output:
11
result:
ok 1 number(s): "11"
Test #5:
score: 0
Accepted
time: 0ms
memory: 9740kb
input:
10 1 BBBBBBBBBBAAAAAAAAAA
output:
100
result:
ok 1 number(s): "100"
Test #6:
score: 0
Accepted
time: 1ms
memory: 9800kb
input:
10 2 BBBBBBBBBBAAAAAAAAAA
output:
75
result:
ok 1 number(s): "75"
Test #7:
score: 0
Accepted
time: 1ms
memory: 9804kb
input:
10 9 BBBBBBBBBBAAAAAAAAAA
output:
56
result:
ok 1 number(s): "56"
Test #8:
score: 0
Accepted
time: 1ms
memory: 9812kb
input:
10 10 BBBBBBBBBBAAAAAAAAAA
output:
55
result:
ok 1 number(s): "55"
Test #9:
score: 0
Accepted
time: 1ms
memory: 9784kb
input:
10 10 ABABABABABABABABABAB
output:
0
result:
ok 1 number(s): "0"
Test #10:
score: 0
Accepted
time: 1ms
memory: 9808kb
input:
10 2 ABAAABABABBBABABABAB
output:
14
result:
ok 1 number(s): "14"
Test #11:
score: 0
Accepted
time: 0ms
memory: 9820kb
input:
10 4 ABAABBAAABBBAAABBBAB
output:
2
result:
ok 1 number(s): "2"
Test #12:
score: 0
Accepted
time: 0ms
memory: 9820kb
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: 2ms
memory: 9744kb
input:
179 54 AAABABABABBAAABBABBABBABBBAAABAAAAABBBABAAAAABABBBAABBBABABBAABABAABABBBBABAABAABABABBBABBAABABBAABBAABABBAAABAAAAAAAABBAAAAABAAABBBBBBBABBAABBBABABAABBAABBABABABBABAAABABAAABABABBAABABAAABBABABABABABBAAABABBBBBBBAABBBAABABBBBABAABBAAAABAABBABABAABAAABABAAAABBBAABAAABBABABBBABAAABAABBBABBBBBA...
output:
41
result:
ok 1 number(s): "41"
Test #14:
score: 0
Accepted
time: 3ms
memory: 9860kb
input:
500 93 ABABAABBBBABAABAABAAAAABABBBBBABABBABAAAABAABBBBABAABBBAAABBABABAAAABAABBABAAABBAAABBBABBAAAAAABABABBBABABBBAABAAABAABABAAABAAABBAAABABBBAABBABBBABBBAABAAAABBBAABBBABAAAAAABABABBBABAAAABBBBBAABBBABAAABAABBBABABAABABBBBABBABBBBBBBABAAAABAABAABBABBBAABBBAAAAAAABBAABAAABBBABBBAAABABBBBAABBBABABB...
output:
235
result:
ok 1 number(s): "235"
Test #15:
score: 0
Accepted
time: 7ms
memory: 9904kb
input:
500 273 AAABBABAABAAABABAABBBABAAAABBAAABBABAAABBABABAAAABBBAAABBBAABAABAABBABABABABBAAABBBBBBBAABABBAABABBBAABBBBAAABAAAABABBABBBBBAABAABABAAAABBABABABAAAABBBAAAAABABBAABABABAAABBABAAAABABBBAAABABAABBAABBBAABAABBBAABABBBBABAAABAABBBBABBABAAABABBAABABBABBBBBBBABAABAAAABABABAAABABABABAABBAABBBABBBAAB...
output:
0
result:
ok 1 number(s): "0"
Test #16:
score: 0
Accepted
time: 6ms
memory: 9828kb
input:
500 1 BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...
output:
250000
result:
ok 1 number(s): "250000"
Test #17:
score: 0
Accepted
time: 3ms
memory: 9840kb
input:
500 2 BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...
output:
187500
result:
ok 1 number(s): "187500"
Test #18:
score: 0
Accepted
time: 6ms
memory: 11952kb
input:
500 499 BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...
output:
125251
result:
ok 1 number(s): "125251"
Test #19:
score: 0
Accepted
time: 6ms
memory: 9808kb
input:
500 500 BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...
output:
125250
result:
ok 1 number(s): "125250"
Test #20:
score: 0
Accepted
time: 7ms
memory: 9824kb
input:
500 10 ABAAABBBAABBABABAABAABABBBAABABABBAABABAABAABABABBBBABAABBAAAAAAABAABAABAABBABBABABBBABABBAABABBBBAABBBBABAAAAAAABAABAAABABABBAABABBABBAAAABAABBBAABABBABABBBBAAAABABBAAAAABAABBBBBBBBABBABBBAABBABBAAAABAABBBBBBAABBBAAAABABBAAABAABAABBBBAABBAAABBAABBAAAAABAAAAAABBAABABBABABBBABAAABBBAAABABAAABB...
output:
9129
result:
ok 1 number(s): "9129"
Test #21:
score: 0
Accepted
time: 3ms
memory: 9780kb
input:
500 500 ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB...
output:
0
result:
ok 1 number(s): "0"
Test #22:
score: 0
Accepted
time: 6ms
memory: 9908kb
input:
500 416 ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB...
output:
84
result:
ok 1 number(s): "84"
Test #23:
score: 0
Accepted
time: 6ms
memory: 9900kb
input:
499 167 ABAABBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAAB...
output:
2
result:
ok 1 number(s): "2"
Test #24:
score: 0
Accepted
time: 6ms
memory: 9760kb
input:
499 167 ABAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAA...
output:
2
result:
ok 1 number(s): "2"
Subtask #3:
score: 0
Wrong Answer
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Test #25:
score: 21
Accepted
time: 453ms
memory: 10064kb
input:
4918 2048 ABBBBBBAAAAABBBBAAAABBABBAAAABBBAABBBABABBAAAABBBAAAABAABBAAABAAABAABBAAABAAABBBAABBBBBBABAABBBBAAAAABBBBBABBBABABBBBBABAAAAAABAABBABBABBBBBAABAABAAAAAABBBBBAABBBABBBAAABBABBABBBAABBBBBBABBBABAABABABABABAAABBABABBAABAABBBBABABBAABABABABBAABABABBABABABAAABABBBABBBABBABBBBAAAABBBBAAABBBABBBA...
output:
138308
result:
ok 1 number(s): "138308"
Test #26:
score: 0
Accepted
time: 472ms
memory: 10120kb
input:
5000 4332 AABBBABBBABBBABBAABABABAAAABAAABBABABBBABBBBBABABAAAAABAAAAAAABBBBABBBABABABBABAABAABBBBABBABBBAABABABBAABBAABABAAABBBABABBABBBBBABBAAABBABBAAAABAAABBBAAABBAABBABAAABABAABBAAABBABABABAAABBBAAAABAAAABAABBAABBAAABBABAAABBABAABBBABABBBBABBBAAABBBABBABBABBABBAAABABAAAAAAABABBBAAABABBBAABBAABAA...
output:
999
result:
ok 1 number(s): "999"
Test #27:
score: 0
Accepted
time: 462ms
memory: 10044kb
input:
5000 1029 AAAAAAABAABBBAAABBBAABBABAABBBABBBBABAABAABBBBABAAAABBBAAAABBABABABABBBAAABAAABABBAAABAABAABAAAAAABAAABBBABBBABBBABBABAAAAAABBABABBBAAAAABBBAAAAAAAABBAABABAABBBAAAABBBBABBABBBAABBAAABBBBABAABABBBBBABBBAAAABAABBAAABBAAABAAAAAABAAABABBBAAAAABBBAAABBBAAAAABBABBABBBAAABAABABBBABBABBAABABBAAABA...
output:
0
result:
ok 1 number(s): "0"
Test #28:
score: 0
Accepted
time: 427ms
memory: 9896kb
input:
5000 1 BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...
output:
25000000
result:
ok 1 number(s): "25000000"
Test #29:
score: 0
Accepted
time: 439ms
memory: 9992kb
input:
5000 2 BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...
output:
18750000
result:
ok 1 number(s): "18750000"
Test #30:
score: 0
Accepted
time: 440ms
memory: 10052kb
input:
5000 4999 BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...
output:
12502501
result:
ok 1 number(s): "12502501"
Test #31:
score: 0
Accepted
time: 440ms
memory: 10048kb
input:
5000 5000 BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...
output:
12502500
result:
ok 1 number(s): "12502500"
Test #32:
score: 0
Accepted
time: 453ms
memory: 10016kb
input:
5000 10 ABABAABBAAAABAABBABBBBABAAABBBAAABAABAAABAAABAAABBBBBBBAAAABAABAABAAABBBAAABAAABABABABBABBAABABBABBAAAAABABABABAAABBBBABAABBABBBABBAABAABBBAAAAABBBAABABABBAAABBAAABAABAAABABAAABAAABAABAAAAABBBBBBBAABABAABBBBAABBAABAABABAAAABBBBBAABBBBBABAABAABABABAAAAABBBAAAABAABABBBABBAABABABAAAABAABBBAAAAB...
output:
1155101
result:
ok 1 number(s): "1155101"
Test #33:
score: -21
Wrong Answer
time: 449ms
memory: 10116kb
input:
5000 1000 AABABBABABAAAABABABBABBABAAABABBABABAABBAABABBBBAABBABABABABAABBABABAAAABBBAAABBAABABBABBBAABBAAABABBAABABABBAABAABABBAABABBBBABAABAABABBBAAABBBABABABAABBAAAABBAABBAABBABABBBABABAABBAAAABBBAABABABBBABABAAABBABBAAAABABABABBABBBABABAAAABABBBAABABBBABABABABABAAABBBAABABBABABABABABAAAABABABABA...
output:
4216
result:
wrong answer 1st numbers differ - expected: '4212', found: '4216'
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%