QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#454457#6338. Chorussnpmrnhlol100 ✓1557ms70784kbC++142.5kb2024-06-24 22:02:592024-06-24 22:02:59

Judging History

你现在查看的是最新测评结果

  • [2024-06-24 22:02:59]
  • 评测
  • 测评结果:100
  • 用时:1557ms
  • 内存:70784kb
  • [2024-06-24 22:02:59]
  • 提交

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});
        pt = min(pt,sz - 1);
        sz++;
    }
    pair<ll,ll> get(ll x){
        assert(sz != 0);
        pt = max(pt,0ll);
        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};
        while(pt < i && 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(pt != i){
            dp[i] = min(dp[i],{dp[pt].first + x,dp[pt].second + 1});
        }
        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;
}

详细

Subtask #1:

score: 16
Accepted

Test #1:

score: 16
Accepted
time: 0ms
memory: 9700kb

input:

1 1
BA

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 0
Accepted
time: 0ms
memory: 9776kb

input:

7 5
ABBAAABBABABBA

output:

3

result:

ok 1 number(s): "3"

Test #3:

score: 0
Accepted
time: 1ms
memory: 9856kb

input:

10 3
BABBABAABAABBABBBAAA

output:

26

result:

ok 1 number(s): "26"

Test #4:

score: 0
Accepted
time: 1ms
memory: 9832kb

input:

10 2
AAABBABABBAAABBBAABB

output:

11

result:

ok 1 number(s): "11"

Test #5:

score: 0
Accepted
time: 1ms
memory: 9848kb

input:

10 1
BBBBBBBBBBAAAAAAAAAA

output:

100

result:

ok 1 number(s): "100"

Test #6:

score: 0
Accepted
time: 1ms
memory: 9772kb

input:

10 2
BBBBBBBBBBAAAAAAAAAA

output:

75

result:

ok 1 number(s): "75"

Test #7:

score: 0
Accepted
time: 1ms
memory: 9700kb

input:

10 9
BBBBBBBBBBAAAAAAAAAA

output:

56

result:

ok 1 number(s): "56"

Test #8:

score: 0
Accepted
time: 1ms
memory: 9784kb

input:

10 10
BBBBBBBBBBAAAAAAAAAA

output:

55

result:

ok 1 number(s): "55"

Test #9:

score: 0
Accepted
time: 1ms
memory: 9760kb

input:

10 10
ABABABABABABABABABAB

output:

0

result:

ok 1 number(s): "0"

Test #10:

score: 0
Accepted
time: 1ms
memory: 9852kb

input:

10 2
ABAAABABABBBABABABAB

output:

14

result:

ok 1 number(s): "14"

Test #11:

score: 0
Accepted
time: 1ms
memory: 9856kb

input:

10 4
ABAABBAAABBBAAABBBAB

output:

2

result:

ok 1 number(s): "2"

Test #12:

score: 0
Accepted
time: 1ms
memory: 9692kb

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: 0ms
memory: 9764kb

input:

179 54
AAABABABABBAAABBABBABBABBBAAABAAAAABBBABAAAAABABBBAABBBABABBAABABAABABBBBABAABAABABABBBABBAABABBAABBAABABBAAABAAAAAAAABBAAAAABAAABBBBBBBABBAABBBABABAABBAABBABABABBABAAABABAAABABABBAABABAAABBABABABABABBAAABABBBBBBBAABBBAABABBBBABAABBAAAABAABBABABAABAAABABAAAABBBAABAAABBABABBBABAAABAABBBABBBBBA...

output:

41

result:

ok 1 number(s): "41"

Test #14:

score: 0
Accepted
time: 1ms
memory: 9828kb

input:

500 93
ABABAABBBBABAABAABAAAAABABBBBBABABBABAAAABAABBBBABAABBBAAABBABABAAAABAABBABAAABBAAABBBABBAAAAAABABABBBABABBBAABAAABAABABAAABAAABBAAABABBBAABBABBBABBBAABAAAABBBAABBBABAAAAAABABABBBABAAAABBBBBAABBBABAAABAABBBABABAABABBBBABBABBBBBBBABAAAABAABAABBABBBAABBBAAAAAAABBAABAAABBBABBBAAABABBBBAABBBABABB...

output:

235

result:

ok 1 number(s): "235"

Test #15:

score: 0
Accepted
time: 2ms
memory: 9812kb

input:

500 273
AAABBABAABAAABABAABBBABAAAABBAAABBABAAABBABABAAAABBBAAABBBAABAABAABBABABABABBAAABBBBBBBAABABBAABABBBAABBBBAAABAAAABABBABBBBBAABAABABAAAABBABABABAAAABBBAAAAABABBAABABABAAABBABAAAABABBBAAABABAABBAABBBAABAABBBAABABBBBABAAABAABBBBABBABAAABABBAABABBABBBBBBBABAABAAAABABABAAABABABABAABBAABBBABBBAAB...

output:

0

result:

ok 1 number(s): "0"

Test #16:

score: 0
Accepted
time: 1ms
memory: 9800kb

input:

500 1
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...

output:

250000

result:

ok 1 number(s): "250000"

Test #17:

score: 0
Accepted
time: 1ms
memory: 9876kb

input:

500 2
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...

output:

187500

result:

ok 1 number(s): "187500"

Test #18:

score: 0
Accepted
time: 1ms
memory: 9816kb

input:

500 499
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...

output:

125251

result:

ok 1 number(s): "125251"

Test #19:

score: 0
Accepted
time: 1ms
memory: 9712kb

input:

500 500
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...

output:

125250

result:

ok 1 number(s): "125250"

Test #20:

score: 0
Accepted
time: 1ms
memory: 9880kb

input:

500 10
ABAAABBBAABBABABAABAABABBBAABABABBAABABAABAABABABBBBABAABBAAAAAAABAABAABAABBABBABABBBABABBAABABBBBAABBBBABAAAAAAABAABAAABABABBAABABBABBAAAABAABBBAABABBABABBBBAAAABABBAAAAABAABBBBBBBBABBABBBAABBABBAAAABAABBBBBBAABBBAAAABABBAAABAABAABBBBAABBAAABBAABBAAAAABAAAAAABBAABABBABABBBABAAABBBAAABABAAABB...

output:

9129

result:

ok 1 number(s): "9129"

Test #21:

score: 0
Accepted
time: 1ms
memory: 9796kb

input:

500 500
ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB...

output:

0

result:

ok 1 number(s): "0"

Test #22:

score: 0
Accepted
time: 1ms
memory: 9764kb

input:

500 416
ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB...

output:

84

result:

ok 1 number(s): "84"

Test #23:

score: 0
Accepted
time: 0ms
memory: 9780kb

input:

499 167
ABAABBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAAB...

output:

2

result:

ok 1 number(s): "2"

Test #24:

score: 0
Accepted
time: 1ms
memory: 9808kb

input:

499 167
ABAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAA...

output:

2

result:

ok 1 number(s): "2"

Subtask #3:

score: 21
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Test #25:

score: 21
Accepted
time: 6ms
memory: 10096kb

input:

4918 2048
ABBBBBBAAAAABBBBAAAABBABBAAAABBBAABBBABABBAAAABBBAAAABAABBAAABAAABAABBAAABAAABBBAABBBBBBABAABBBBAAAAABBBBBABBBABABBBBBABAAAAAABAABBABBABBBBBAABAABAAAAAABBBBBAABBBABBBAAABBABBABBBAABBBBBBABBBABAABABABABABAAABBABABBAABAABBBBABABBAABABABABBAABABABBABABABAAABABBBABBBABBABBBBAAAABBBBAAABBBABBBA...

output:

138308

result:

ok 1 number(s): "138308"

Test #26:

score: 0
Accepted
time: 7ms
memory: 10024kb

input:

5000 4332
AABBBABBBABBBABBAABABABAAAABAAABBABABBBABBBBBABABAAAAABAAAAAAABBBBABBBABABABBABAABAABBBBABBABBBAABABABBAABBAABABAAABBBABABBABBBBBABBAAABBABBAAAABAAABBBAAABBAABBABAAABABAABBAAABBABABABAAABBBAAAABAAAABAABBAABBAAABBABAAABBABAABBBABABBBBABBBAAABBBABBABBABBABBAAABABAAAAAAABABBBAAABABBBAABBAABAA...

output:

999

result:

ok 1 number(s): "999"

Test #27:

score: 0
Accepted
time: 3ms
memory: 10040kb

input:

5000 1029
AAAAAAABAABBBAAABBBAABBABAABBBABBBBABAABAABBBBABAAAABBBAAAABBABABABABBBAAABAAABABBAAABAABAABAAAAAABAAABBBABBBABBBABBABAAAAAABBABABBBAAAAABBBAAAAAAAABBAABABAABBBAAAABBBBABBABBBAABBAAABBBBABAABABBBBBABBBAAAABAABBAAABBAAABAAAAAABAAABABBBAAAAABBBAAABBBAAAAABBABBABBBAAABAABABBBABBABBAABABBAAABA...

output:

0

result:

ok 1 number(s): "0"

Test #28:

score: 0
Accepted
time: 6ms
memory: 9892kb

input:

5000 1
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...

output:

25000000

result:

ok 1 number(s): "25000000"

Test #29:

score: 0
Accepted
time: 5ms
memory: 10036kb

input:

5000 2
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...

output:

18750000

result:

ok 1 number(s): "18750000"

Test #30:

score: 0
Accepted
time: 5ms
memory: 10008kb

input:

5000 4999
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...

output:

12502501

result:

ok 1 number(s): "12502501"

Test #31:

score: 0
Accepted
time: 3ms
memory: 10036kb

input:

5000 5000
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...

output:

12502500

result:

ok 1 number(s): "12502500"

Test #32:

score: 0
Accepted
time: 3ms
memory: 10004kb

input:

5000 10
ABABAABBAAAABAABBABBBBABAAABBBAAABAABAAABAAABAAABBBBBBBAAAABAABAABAAABBBAAABAAABABABABBABBAABABBABBAAAAABABABABAAABBBBABAABBABBBABBAABAABBBAAAAABBBAABABABBAAABBAAABAABAAABABAAABAAABAABAAAAABBBBBBBAABABAABBBBAABBAABAABABAAAABBBBBAABBBBBABAABAABABABAAAAABBBAAAABAABABBBABBAABABABAAAABAABBBAAAAB...

output:

1155101

result:

ok 1 number(s): "1155101"

Test #33:

score: 0
Accepted
time: 7ms
memory: 10096kb

input:

5000 1000
AABABBABABAAAABABABBABBABAAABABBABABAABBAABABBBBAABBABABABABAABBABABAAAABBBAAABBAABABBABBBAABBAAABABBAABABABBAABAABABBAABABBBBABAABAABABBBAAABBBABABABAABBAAAABBAABBAABBABABBBABABAABBAAAABBBAABABABBBABABAAABBABBAAAABABABABBABBBABABAAAABABBBAABABBBABABABABABAAABBBAABABBABABABABABAAAABABABABA...

output:

4212

result:

ok 1 number(s): "4212"

Test #34:

score: 0
Accepted
time: 3ms
memory: 12104kb

input:

5000 4138
ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB...

output:

862

result:

ok 1 number(s): "862"

Test #35:

score: 0
Accepted
time: 6ms
memory: 9972kb

input:

5000 2379
ABAABABABABBABABAABABBABABAABABBAABBABABAABABABBAABABABABBABABAABABBAABBABABAABBABAABABABABBABABAABBABABABABAABABABBAABABABABBAABABBAABBABAABABABABBABAABABBAABBAABBABAABABABBABABAABABBAABBABABABAABBABABABAABBABABAABABABABBABABAABABABBABAABBAABABBABAABABBABABAABBABABABABABAABABBABABAABBAABB...

output:

1071

result:

ok 1 number(s): "1071"

Test #36:

score: 0
Accepted
time: 5ms
memory: 9932kb

input:

4999 1667
ABAABBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAA...

output:

2

result:

ok 1 number(s): "2"

Test #37:

score: 0
Accepted
time: 5ms
memory: 10000kb

input:

4999 1667
ABAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBB...

output:

2

result:

ok 1 number(s): "2"

Test #38:

score: 0
Accepted
time: 4ms
memory: 9932kb

input:

5000 1665
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...

output:

1388613

result:

ok 1 number(s): "1388613"

Subtask #4:

score: 26
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Test #39:

score: 26
Accepted
time: 75ms
memory: 13044kb

input:

59936 57569
BAAABBAAABBBABABAABABBAAABABABBABBAABABBBABBABABBBABABAABBBBAABABABAABAAAAAABABAAABBBBBABAAAABAAAABBAAABAAAAAABBAABAAABABAAABAABBABBBBBBABBBBABBAABBBABBBABAABAABAAABABBBBAAABAAAAAAABBABBAABABABBBAAABABBAABABBABAAAABABBBABABAAAABBABBBBBBAABBBBABBABBBAAAABAAAAAABBAAAABBBBBBBBAABBBBABABABBA...

output:

33013

result:

ok 1 number(s): "33013"

Test #40:

score: 0
Accepted
time: 136ms
memory: 15328kb

input:

100000 8782
ABBABAAAABBBBBABAAABABAABBABABAABAABAABBABBAAAAAABBAAAABBBAAABBABAAAAAABBAABAABABAAAAABABAAABBBABBAABBABABBBABBAAAABBBBABABAAABAAAAAAABBBAABABBBBBABABBAABABAAABBBAAABABBBBBABBAAAAABAAAAAABBBAABAABBABABBAAAAAAABAABBBBAABBABABBAAABBAAABAABABBBABAABBAAABABABAABBBBABAAABABAAAABAAAABBBAABAAAA...

output:

198328

result:

ok 1 number(s): "198328"

Test #41:

score: 0
Accepted
time: 137ms
memory: 18844kb

input:

100000 38214
AAABBABBAABABAAABABAABBAABBBBAAAAAABAAABABAABABAAAAABABBBBABAAAAABBAAAABABAABBBAABAAABBAAABAAABBAABBBABABBBBABAABABAAABBAAABBBBAABABABBAAAABBABAAABBBBABBABABAABAAABBBAABBABABABBABBAAAABABBBBBBBBABBAABABBBBAABBBBAABBBAAAAAABAABABAABBAABAABAABBAABABAAAABAABABBABAABBBAAABAABAABAAABAABBAABA...

output:

0

result:

ok 1 number(s): "0"

Test #42:

score: 0
Accepted
time: 98ms
memory: 17628kb

input:

100000 1
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...

output:

10000000000

result:

ok 1 number(s): "10000000000"

Test #43:

score: 0
Accepted
time: 89ms
memory: 12224kb

input:

100000 2
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...

output:

7500000000

result:

ok 1 number(s): "7500000000"

Test #44:

score: 0
Accepted
time: 88ms
memory: 19968kb

input:

100000 99999
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...

output:

5000050001

result:

ok 1 number(s): "5000050001"

Test #45:

score: 0
Accepted
time: 84ms
memory: 19536kb

input:

100000 100000
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...

output:

5000050000

result:

ok 1 number(s): "5000050000"

Test #46:

score: 0
Accepted
time: 147ms
memory: 15476kb

input:

100000 10
AABBABABAAABAABBAABBAABABABABBBBABAAAABAABAABBABBBABABBAABAABABBBABAABAAABABBBBAABBBAABAABBABBABAABABAAAABBBAAABBBABBBABAAAABBABAAAABAABBBBABBABBAABBBAAAABABBBABABAABABABABBAABBABAAABAAAAABABBBBBAAAABAABAAAABBABBABBAABABBBBBBABAABABBBABBBABAABBABABABAAAABABBBAAABBAABBBAABBBAAABBAAAABABBBBB...

output:

485360890

result:

ok 1 number(s): "485360890"

Test #47:

score: 0
Accepted
time: 149ms
memory: 18852kb

input:

100000 1000
ABAAAABBABAABBAAAAABBBABABAABAAAAAABABABABBAABBAAABAAABBAAABABBBBBABAABAAAABBBAABBBBBAAABAAAAAABABBBBAAAABBABBBABAABBAAABBABBBABBBBBABBBBBABAABABABBBBAABBABABABABAABABBAAAAAABABBBABBABBAAAABBBAAABBBBBBABAABBABAAAAABAABAAABBAABABAABBABAAAABABABABAAABBBBABAAAABAABABABBBABAABABABAAABAAABAAA...

output:

2235279

result:

ok 1 number(s): "2235279"

Test #48:

score: 0
Accepted
time: 84ms
memory: 16992kb

input:

100000 100000
ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB...

output:

0

result:

ok 1 number(s): "0"

Test #49:

score: 0
Accepted
time: 88ms
memory: 20432kb

input:

100000 76937
ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA...

output:

23063

result:

ok 1 number(s): "23063"

Test #50:

score: 0
Accepted
time: 142ms
memory: 15892kb

input:

100000 12845
AABBABABABAAAAABBBABABABBAABAABABBBAAAABABAABAABBBBAAABBABBABBAAAABBBABABBBBABABAABBAAABABBAAABBBBAAAABBBAAABBBAAABABABABAABAABBABBABBAAAAABBBBBABBBABABAAAABABABAAAABBBBAAABAABABBBBBABBBAABAAAABABBBAAABBAAABAABABABABBBBBBBAABABBABABAABBABAAAABBBBAAABBBABAAABAAABBBBBAABBABABAABBAABBAABAA...

output:

118675

result:

ok 1 number(s): "118675"

Subtask #5:

score: 13
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Test #51:

score: 13
Accepted
time: 917ms
memory: 53288kb

input:

644992 518558
BBBAABABBAABBBABABBABABBABABAABABBAAABAAABABBBAABAABBAABAABABABAABAABABBBBBABBABABBABABBBBBBBBBBAABBBBBABBAABABBABBBABBBABBAAABABABAABBABABAABAAAAABABBBBBBABAABAAABBAAABBBBBAAABABAABABABAAAABAAABABABAABBABABBABAAABAAABBBABABAABBBAABABAABBBBABBBBABBAAAABBBAAAABAAAABBBBAAABBABBBBABABBBBA...

output:

141233

result:

ok 1 number(s): "141233"

Test #52:

score: 0
Accepted
time: 1125ms
memory: 69604kb

input:

1000000 810099
AABBBABAAAABBBBBABABABAAABBBBABAABBBBBBBABAABBBBBAAABABABBBAAABBBBAABABABAAAABABABBABABABBABABABBAAABAAAAABBAABABABBAABBBBABBBABBAAAABBBBBAABAABBAAAAABBAABBBAAABAABAABAABAAABBBBABAABABAAAABBBBABBABBBABBBBABBAAABABAABABBBAABAAAABBBABABBABABBAABAABBBBBAABABABAABABABBBBBABABAAAAABBBBABAB...

output:

121661020

result:

ok 1 number(s): "121661020"

Test #53:

score: 0
Accepted
time: 1426ms
memory: 56916kb

input:

1000000 68584
AABAAAAABAABBBAABBBAABAABAAABBAABAAABBABBAAABABBBBAAAABABABAABBBBABABAAAABBBBBBBAAAAAABBBABBAAABAAAABABBBBAAAAABBBAAAABBABBABABAAABABBBBBABABAAABBABAAABABBBBABBAABABBBBBBBBAABAAABBABAAAABABBBAABAABAABBBBAAAABBBBBAAABABABAABAAAAAAAAAABABBABABABAAAABAAAAABAABABBAAABBABBBBBABAABAABAABAAAA...

output:

0

result:

ok 1 number(s): "0"

Test #54:

score: 0
Accepted
time: 957ms
memory: 44604kb

input:

1000000 1
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...

output:

1000000000000

result:

ok 1 number(s): "1000000000000"

Test #55:

score: 0
Accepted
time: 853ms
memory: 57080kb

input:

1000000 2
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...

output:

750000000000

result:

ok 1 number(s): "750000000000"

Test #56:

score: 0
Accepted
time: 802ms
memory: 69044kb

input:

1000000 999999
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...

output:

500000500001

result:

ok 1 number(s): "500000500001"

Test #57:

score: 0
Accepted
time: 801ms
memory: 69120kb

input:

1000000 1000000
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...

output:

500000500000

result:

ok 1 number(s): "500000500000"

Test #58:

score: 0
Accepted
time: 1519ms
memory: 57520kb

input:

1000000 10
ABABABABABABAAABABBBAAAABABBBBABABABABAAABAABABBAABBBBAABBAAAABBBBAABBAAAABABBABAABABBBBAAABABBABAAAABABBAABABAABABABABAABBBBBABABBBABABAAAAAABBAABAABABAABABBBAABBABBAABBBBBABAAAAABBABAAAABBABBAABBBBBABBAABABBBAAAAAABAAABAABAAAABBBBBBABBAABBBAAAAABABBBABAAAAAABABBABBBBBABBBABABBABAABAABBA...

output:

49686369526

result:

ok 1 number(s): "49686369526"

Test #59:

score: 0
Accepted
time: 1557ms
memory: 56772kb

input:

1000000 1000
ABABAAAABBBAAABBABBBABABABAAABAABABABAABABABBBBBAAAAAABAAAAABAABABABABABBABBBBAAAAABAABBAAABBAABAABBBABBAAABAAABABABBBBABABABBABBBABAABBBABBBABBABAAABABABBBAABBBABBBAAAABAAAABBAAABAABABABABBBABABABBBBBBAABBABABBBAABAABAABBABBBABABAAAABABAAAAABBAAAAABAABBABBAABAABAABAABBABBBAAAAABAAABBBA...

output:

179680697

result:

ok 1 number(s): "179680697"

Test #60:

score: 0
Accepted
time: 823ms
memory: 69084kb

input:

1000000 100000
ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA...

output:

4500000

result:

ok 1 number(s): "4500000"

Test #61:

score: 0
Accepted
time: 865ms
memory: 70784kb

input:

1000000 745782
ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA...

output:

254218

result:

ok 1 number(s): "254218"

Test #62:

score: 0
Accepted
time: 1498ms
memory: 56820kb

input:

1000000 96140
AAABBABABBABAABBAAAAAABABBBAABBABAAABABBAABABABBABBBABBAABBAAABBABBBAAAAABBAABBBAAAABABBBABBBABBABAABABABBAAAAAABABABABBBBAAABBBAABABBBABBABAAAABBAABAAABABBBBBAABABBBABAABBABAABABBAABBAABBAABABBAABABABBABABAAABBBABABAABABBABABAABAAAABBBABBAABBBABAAAABBABBABABAABAAABBABABBABBABBAABAABBB...

output:

2580941

result:

ok 1 number(s): "2580941"

Test #63:

score: 0
Accepted
time: 851ms
memory: 69724kb

input:

1000000 721685
ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA...

output:

278315

result:

ok 1 number(s): "278315"

Extra Test:

score: 0
Extra Test Passed