QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#668106#6338. ChorusL_Hospital_#87 4292ms48168kbC++141.8kb2024-10-23 11:26:432024-10-23 11:26:49

Judging History

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

  • [2024-10-23 11:26:49]
  • 评测
  • 测评结果:87
  • 用时:4292ms
  • 内存:48168kb
  • [2024-10-23 11:26:43]
  • 提交

answer

#include<bits/stdc++.h>
# define int long long
# define rep(i, j, k) for (int i = j; i <= k; ++i)
# define inf 4000000000000000000LL
using namespace std;

int n, k;
string s;
int b[1000005], dla[1000005], pre[1000005];
int dp[1000005], cnt[1000005], stk[1000005], l, r, pas[1000005];
int calc(int l, int r)
{
    if (b[r] <= r) return (r - l + 1) * r - pre[r] + pre[l - 1];
    if (b[l] >= r) return 0;
    return (dla[r - 1] - l + 1) * r - pre[dla[r - 1]] + pre[l - 1];
}
int ef(int x, int y)
{
    int l = y, r = n + 1;
    while (r - l > 1)
    {
        int mid = ((l + r) >> 1), tx = dp[x] + calc(x + 1, mid), ty = dp[y] + calc(y + 1, mid);
        if (tx < ty || tx == ty && cnt[x] < cnt[y]) l = mid; else r = mid;
    }
    return r;
}
int check(int x)
{
    stk[l = r = 1] = 0;
    rep(i, 1, n)
    {
        while (l < r && pas[l] <= i) ++l;
        cnt[i] = cnt[stk[l]] + 1, dp[i] = dp[stk[l]] + calc(stk[l] + 1, i) - x;
        while (l < r && pas[r - 1] > ef(stk[r], i)) --r;
        stk[++r] = i, pas[r - 1] = ef(stk[r - 1], i);
    }
    return cnt[n];
}

signed main()
{
//	freopen("ex_4.in", "r", stdin);
//	freopen("a.out", "w", stdout);
	ios::sync_with_stdio(false); cin.tie(0), cout.tie(0);
	cin >> n >> k >> s;
	int nowa = 0, nowb = 0;
	rep(i, 1, 2 * n) if (s[i - 1] == 'A') dla[nowa++] = nowb; else b[++nowb] = nowa, pre[nowb] = pre[nowb - 1] + b[nowb];
//	rep(i, 0, n) cout << dla[i] << ' ' << b[i] << endl;
	int l = -2e12, r = 1e12;
	while (r - l > 1)
    {
        int mid = (l + r) / 2;
  //      cout << l << ' ' << r << ' ' << mid << endl;
        if (check(mid) <= k) l = mid; else r = mid;
    }
    check(l);
  //  cout << l << endl;
 //   rep(i, 1, n) cout << dp[i] << ' '; cout << endl;
  //  rep(i, 1, n) cout << cnt[i] << ' '; cout << endl;
    cout << dp[n] + k * l << '\n';
    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: 9776kb

input:

1 1
BA

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 16
Accepted
time: 1ms
memory: 9720kb

input:

7 5
ABBAAABBABABBA

output:

3

result:

ok 1 number(s): "3"

Test #3:

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

input:

10 3
BABBABAABAABBABBBAAA

output:

26

result:

ok 1 number(s): "26"

Test #4:

score: 16
Accepted
time: 2ms
memory: 9768kb

input:

10 2
AAABBABABBAAABBBAABB

output:

11

result:

ok 1 number(s): "11"

Test #5:

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

input:

10 1
BBBBBBBBBBAAAAAAAAAA

output:

100

result:

ok 1 number(s): "100"

Test #6:

score: 16
Accepted
time: 1ms
memory: 9768kb

input:

10 2
BBBBBBBBBBAAAAAAAAAA

output:

75

result:

ok 1 number(s): "75"

Test #7:

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

input:

10 9
BBBBBBBBBBAAAAAAAAAA

output:

56

result:

ok 1 number(s): "56"

Test #8:

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

input:

10 10
BBBBBBBBBBAAAAAAAAAA

output:

55

result:

ok 1 number(s): "55"

Test #9:

score: 16
Accepted
time: 1ms
memory: 9776kb

input:

10 10
ABABABABABABABABABAB

output:

0

result:

ok 1 number(s): "0"

Test #10:

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

input:

10 2
ABAAABABABBBABABABAB

output:

14

result:

ok 1 number(s): "14"

Test #11:

score: 16
Accepted
time: 1ms
memory: 9836kb

input:

10 4
ABAABBAAABBBAAABBBAB

output:

2

result:

ok 1 number(s): "2"

Test #12:

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

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: 9844kb

input:

179 54
AAABABABABBAAABBABBABBABBBAAABAAAAABBBABAAAAABABBBAABBBABABBAABABAABABBBBABAABAABABABBBABBAABABBAABBAABABBAAABAAAAAAAABBAAAAABAAABBBBBBBABBAABBBABABAABBAABBABABABBABAAABABAAABABABBAABABAAABBABABABABABBAAABABBBBBBBAABBBAABABBBBABAABBAAAABAABBABABAABAAABABAAAABBBAABAAABBABABBBABAAABAABBBABBBBBA...

output:

41

result:

ok 1 number(s): "41"

Test #14:

score: 24
Accepted
time: 3ms
memory: 9780kb

input:

500 93
ABABAABBBBABAABAABAAAAABABBBBBABABBABAAAABAABBBBABAABBBAAABBABABAAAABAABBABAAABBAAABBBABBAAAAAABABABBBABABBBAABAAABAABABAAABAAABBAAABABBBAABBABBBABBBAABAAAABBBAABBBABAAAAAABABABBBABAAAABBBBBAABBBABAAABAABBBABABAABABBBBABBABBBBBBBABAAAABAABAABBABBBAABBBAAAAAAABBAABAAABBBABBBAAABABBBBAABBBABABB...

output:

235

result:

ok 1 number(s): "235"

Test #15:

score: 24
Accepted
time: 3ms
memory: 9848kb

input:

500 273
AAABBABAABAAABABAABBBABAAAABBAAABBABAAABBABABAAAABBBAAABBBAABAABAABBABABABABBAAABBBBBBBAABABBAABABBBAABBBBAAABAAAABABBABBBBBAABAABABAAAABBABABABAAAABBBAAAAABABBAABABABAAABBABAAAABABBBAAABABAABBAABBBAABAABBBAABABBBBABAAABAABBBBABBABAAABABBAABABBABBBBBBBABAABAAAABABABAAABABABABAABBAABBBABBBAAB...

output:

0

result:

ok 1 number(s): "0"

Test #16:

score: 24
Accepted
time: 3ms
memory: 9768kb

input:

500 1
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...

output:

250000

result:

ok 1 number(s): "250000"

Test #17:

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

input:

500 2
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...

output:

187500

result:

ok 1 number(s): "187500"

Test #18:

score: 24
Accepted
time: 3ms
memory: 9716kb

input:

500 499
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...

output:

125251

result:

ok 1 number(s): "125251"

Test #19:

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

input:

500 500
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...

output:

125250

result:

ok 1 number(s): "125250"

Test #20:

score: 24
Accepted
time: 3ms
memory: 9848kb

input:

500 10
ABAAABBBAABBABABAABAABABBBAABABABBAABABAABAABABABBBBABAABBAAAAAAABAABAABAABBABBABABBBABABBAABABBBBAABBBBABAAAAAAABAABAAABABABBAABABBABBAAAABAABBBAABABBABABBBBAAAABABBAAAAABAABBBBBBBBABBABBBAABBABBAAAABAABBBBBBAABBBAAAABABBAAABAABAABBBBAABBAAABBAABBAAAAABAAAAAABBAABABBABABBBABAAABBBAAABABAAABB...

output:

9129

result:

ok 1 number(s): "9129"

Test #21:

score: 24
Accepted
time: 0ms
memory: 9804kb

input:

500 500
ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB...

output:

0

result:

ok 1 number(s): "0"

Test #22:

score: 24
Accepted
time: 3ms
memory: 9792kb

input:

500 416
ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB...

output:

84

result:

ok 1 number(s): "84"

Test #23:

score: 24
Accepted
time: 0ms
memory: 9708kb

input:

499 167
ABAABBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAAB...

output:

2

result:

ok 1 number(s): "2"

Test #24:

score: 24
Accepted
time: 3ms
memory: 9780kb

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: 21ms
memory: 9948kb

input:

4918 2048
ABBBBBBAAAAABBBBAAAABBABBAAAABBBAABBBABABBAAAABBBAAAABAABBAAABAAABAABBAAABAAABBBAABBBBBBABAABBBBAAAAABBBBBABBBABABBBBBABAAAAAABAABBABBABBBBBAABAABAAAAAABBBBBAABBBABBBAAABBABBABBBAABBBBBBABBBABAABABABABABAAABBABABBAABAABBBBABABBAABABABABBAABABABBABABABAAABABBBABBBABBABBBBAAAABBBBAAABBBABBBA...

output:

138308

result:

ok 1 number(s): "138308"

Test #26:

score: 21
Accepted
time: 23ms
memory: 9880kb

input:

5000 4332
AABBBABBBABBBABBAABABABAAAABAAABBABABBBABBBBBABABAAAAABAAAAAAABBBBABBBABABABBABAABAABBBBABBABBBAABABABBAABBAABABAAABBBABABBABBBBBABBAAABBABBAAAABAAABBBAAABBAABBABAAABABAABBAAABBABABABAAABBBAAAABAAAABAABBAABBAAABBABAAABBABAABBBABABBBBABBBAAABBBABBABBABBABBAAABABAAAAAAABABBBAAABABBBAABBAABAA...

output:

999

result:

ok 1 number(s): "999"

Test #27:

score: 21
Accepted
time: 18ms
memory: 9884kb

input:

5000 1029
AAAAAAABAABBBAAABBBAABBABAABBBABBBBABAABAABBBBABAAAABBBAAAABBABABABABBBAAABAAABABBAAABAABAABAAAAAABAAABBBABBBABBBABBABAAAAAABBABABBBAAAAABBBAAAAAAAABBAABABAABBBAAAABBBBABBABBBAABBAAABBBBABAABABBBBBABBBAAAABAABBAAABBAAABAAAAAABAAABABBBAAAAABBBAAABBBAAAAABBABBABBBAAABAABABBBABBABBAABABBAAABA...

output:

0

result:

ok 1 number(s): "0"

Test #28:

score: 21
Accepted
time: 23ms
memory: 9948kb

input:

5000 1
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...

output:

25000000

result:

ok 1 number(s): "25000000"

Test #29:

score: 21
Accepted
time: 25ms
memory: 9940kb

input:

5000 2
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...

output:

18750000

result:

ok 1 number(s): "18750000"

Test #30:

score: 21
Accepted
time: 20ms
memory: 9952kb

input:

5000 4999
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...

output:

12502501

result:

ok 1 number(s): "12502501"

Test #31:

score: 21
Accepted
time: 10ms
memory: 9956kb

input:

5000 5000
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...

output:

12502500

result:

ok 1 number(s): "12502500"

Test #32:

score: 21
Accepted
time: 25ms
memory: 9956kb

input:

5000 10
ABABAABBAAAABAABBABBBBABAAABBBAAABAABAAABAAABAAABBBBBBBAAAABAABAABAAABBBAAABAAABABABABBABBAABABBABBAAAAABABABABAAABBBBABAABBABBBABBAABAABBBAAAAABBBAABABABBAAABBAAABAABAAABABAAABAAABAABAAAAABBBBBBBAABABAABBBBAABBAABAABABAAAABBBBBAABBBBBABAABAABABABAAAAABBBAAAABAABABBBABBAABABABAAAABAABBBAAAAB...

output:

1155101

result:

ok 1 number(s): "1155101"

Test #33:

score: 21
Accepted
time: 31ms
memory: 10020kb

input:

5000 1000
AABABBABABAAAABABABBABBABAAABABBABABAABBAABABBBBAABBABABABABAABBABABAAAABBBAAABBAABABBABBBAABBAAABABBAABABABBAABAABABBAABABBBBABAABAABABBBAAABBBABABABAABBAAAABBAABBAABBABABBBABABAABBAAAABBBAABABABBBABABAAABBABBAAAABABABABBABBBABABAAAABABBBAABABBBABABABABABAAABBBAABABBABABABABABAAAABABABABA...

output:

4212

result:

ok 1 number(s): "4212"

Test #34:

score: 21
Accepted
time: 20ms
memory: 9944kb

input:

5000 4138
ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB...

output:

862

result:

ok 1 number(s): "862"

Test #35:

score: 21
Accepted
time: 33ms
memory: 9880kb

input:

5000 2379
ABAABABABABBABABAABABBABABAABABBAABBABABAABABABBAABABABABBABABAABABBAABBABABAABBABAABABABABBABABAABBABABABABAABABABBAABABABABBAABABBAABBABAABABABABBABAABABBAABBAABBABAABABABBABABAABABBAABBABABABAABBABABABAABBABABAABABABABBABABAABABABBABAABBAABABBABAABABBABABAABBABABABABABAABABBABABAABBAABB...

output:

1071

result:

ok 1 number(s): "1071"

Test #36:

score: 21
Accepted
time: 27ms
memory: 10008kb

input:

4999 1667
ABAABBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAA...

output:

2

result:

ok 1 number(s): "2"

Test #37:

score: 21
Accepted
time: 29ms
memory: 12036kb

input:

4999 1667
ABAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBBAAABBB...

output:

2

result:

ok 1 number(s): "2"

Test #38:

score: 21
Accepted
time: 21ms
memory: 9944kb

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: 323ms
memory: 13572kb

input:

59936 57569
BAAABBAAABBBABABAABABBAAABABABBABBAABABBBABBABABBBABABAABBBBAABABABAABAAAAAABABAAABBBBBABAAAABAAAABBAAABAAAAAABBAABAAABABAAABAABBABBBBBBABBBBABBAABBBABBBABAABAABAAABABBBBAAABAAAAAAABBABBAABABABBBAAABABBAABABBABAAAABABBBABABAAAABBABBBBBBAABBBBABBABBBAAAABAAAAAABBAAAABBBBBBBBAABBBBABABABBA...

output:

33013

result:

ok 1 number(s): "33013"

Test #40:

score: 26
Accepted
time: 585ms
memory: 18468kb

input:

100000 8782
ABBABAAAABBBBBABAAABABAABBABABAABAABAABBABBAAAAAABBAAAABBBAAABBABAAAAAABBAABAABABAAAAABABAAABBBABBAABBABABBBABBAAAABBBBABABAAABAAAAAAABBBAABABBBBBABABBAABABAAABBBAAABABBBBBABBAAAAABAAAAAABBBAABAABBABABBAAAAAAABAABBBBAABBABABBAAABBAAABAABABBBABAABBAAABABABAABBBBABAAABABAAAABAAAABBBAABAAAA...

output:

198328

result:

ok 1 number(s): "198328"

Test #41:

score: 26
Accepted
time: 562ms
memory: 18932kb

input:

100000 38214
AAABBABBAABABAAABABAABBAABBBBAAAAAABAAABABAABABAAAAABABBBBABAAAAABBAAAABABAABBBAABAAABBAAABAAABBAABBBABABBBBABAABABAAABBAAABBBBAABABABBAAAABBABAAABBBBABBABABAABAAABBBAABBABABABBABBAAAABABBBBBBBBABBAABABBBBAABBBBAABBBAAAAAABAABABAABBAABAABAABBAABABAAAABAABABBABAABBBAAABAABAABAAABAABBAABA...

output:

0

result:

ok 1 number(s): "0"

Test #42:

score: 26
Accepted
time: 583ms
memory: 18496kb

input:

100000 1
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...

output:

10000000000

result:

ok 1 number(s): "10000000000"

Test #43:

score: 26
Accepted
time: 653ms
memory: 20768kb

input:

100000 2
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...

output:

7500000000

result:

ok 1 number(s): "7500000000"

Test #44:

score: 26
Accepted
time: 467ms
memory: 18444kb

input:

100000 99999
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...

output:

5000050001

result:

ok 1 number(s): "5000050001"

Test #45:

score: 26
Accepted
time: 324ms
memory: 20624kb

input:

100000 100000
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...

output:

5000050000

result:

ok 1 number(s): "5000050000"

Test #46:

score: 26
Accepted
time: 756ms
memory: 18528kb

input:

100000 10
AABBABABAAABAABBAABBAABABABABBBBABAAAABAABAABBABBBABABBAABAABABBBABAABAAABABBBBAABBBAABAABBABBABAABABAAAABBBAAABBBABBBABAAAABBABAAAABAABBBBABBABBAABBBAAAABABBBABABAABABABABBAABBABAAABAAAAABABBBBBAAAABAABAAAABBABBABBAABABBBBBBABAABABBBABBBABAABBABABABAAAABABBBAAABBAABBBAABBBAAABBAAAABABBBBB...

output:

485360890

result:

ok 1 number(s): "485360890"

Test #47:

score: 26
Accepted
time: 678ms
memory: 16260kb

input:

100000 1000
ABAAAABBABAABBAAAAABBBABABAABAAAAAABABABABBAABBAAABAAABBAAABABBBBBABAABAAAABBBAABBBBBAAABAAAAAABABBBBAAAABBABBBABAABBAAABBABBBABBBBBABBBBBABAABABABBBBAABBABABABABAABABBAAAAAABABBBABBABBAAAABBBAAABBBBBBABAABBABAAAAABAABAAABBAABABAABBABAAAABABABABAAABBBBABAAAABAABABABBBABAABABABAAABAAABAAA...

output:

2235279

result:

ok 1 number(s): "2235279"

Test #48:

score: 26
Accepted
time: 323ms
memory: 16676kb

input:

100000 100000
ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB...

output:

0

result:

ok 1 number(s): "0"

Test #49:

score: 26
Accepted
time: 461ms
memory: 18440kb

input:

100000 76937
ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA...

output:

23063

result:

ok 1 number(s): "23063"

Test #50:

score: 26
Accepted
time: 740ms
memory: 19076kb

input:

100000 12845
AABBABABABAAAAABBBABABABBAABAABABBBAAAABABAABAABBBBAAABBABBABBAAAABBBABABBBBABABAABBAAABABBAAABBBBAAAABBBAAABBBAAABABABABAABAABBABBABBAAAAABBBBBABBBABABAAAABABABAAAABBBBAAABAABABBBBBABBBAABAAAABABBBAAABBAAABAABABABABBBBBBBAABABBABABAABBABAAAABBBBAAABBBABAAABAAABBBBBAABBABABAABBAABBAABAA...

output:

118675

result:

ok 1 number(s): "118675"

Subtask #5:

score: 0
Time Limit Exceeded

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Test #51:

score: 13
Accepted
time: 4292ms
memory: 48168kb

input:

644992 518558
BBBAABABBAABBBABABBABABBABABAABABBAAABAAABABBBAABAABBAABAABABABAABAABABBBBBABBABABBABABBBBBBBBBBAABBBBBABBAABABBABBBABBBABBAAABABABAABBABABAABAAAAABABBBBBBABAABAAABBAAABBBBBAAABABAABABABAAAABAAABABABAABBABABBABAAABAAABBBABABAABBBAABABAABBBBABBBBABBAAAABBBAAAABAAAABBBBAAABBABBBBABABBBBA...

output:

141233

result:

ok 1 number(s): "141233"

Test #52:

score: 0
Time Limit Exceeded

input:

1000000 810099
AABBBABAAAABBBBBABABABAAABBBBABAABBBBBBBABAABBBBBAAABABABBBAAABBBBAABABABAAAABABABBABABABBABABABBAAABAAAAABBAABABABBAABBBBABBBABBAAAABBBBBAABAABBAAAAABBAABBBAAABAABAABAABAAABBBBABAABABAAAABBBBABBABBBABBBBABBAAABABAABABBBAABAAAABBBABABBABABBAABAABBBBBAABABABAABABABBBBBABABAAAAABBBBABAB...

output:


result: