QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#784695#4950. Finding Maximal Non-Trivial MonotonesYarema#AC ✓1ms3948kbC++20768b2024-11-26 15:44:252024-11-26 15:44:30

Judging History

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

  • [2024-11-26 15:44:30]
  • 评测
  • 测评结果:AC
  • 用时:1ms
  • 内存:3948kb
  • [2024-11-26 15:44:25]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef double db;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n;
	cin >> n;
	string s;
	cin >> s;
	int ans = 0;
	FOR (i, 0, n)
	{
		int j = i + 1;
		while (j < n && s[j] == s[i])
			j++;
		if (s[i] == 'a' && j - i > 1)
			ans += j - i;
		i = j - 1;
	}
	cout << ans << '\n';
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3744kb

input:

7
abababa

output:

0

result:

ok 1 number(s): "0"

Test #2:

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

input:

7
bababab

output:

0

result:

ok 1 number(s): "0"

Test #3:

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

input:

10
aababaaabb

output:

5

result:

ok 1 number(s): "5"

Test #4:

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

input:

10
bbaababaaa

output:

5

result:

ok 1 number(s): "5"

Test #5:

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

input:

2
bb

output:

0

result:

ok 1 number(s): "0"

Test #6:

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

input:

2
ba

output:

0

result:

ok 1 number(s): "0"

Test #7:

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

input:

2
aa

output:

2

result:

ok 1 number(s): "2"

Test #8:

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

input:

2
bb

output:

0

result:

ok 1 number(s): "0"

Test #9:

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

input:

2
ab

output:

0

result:

ok 1 number(s): "0"

Test #10:

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

input:

2
ab

output:

0

result:

ok 1 number(s): "0"

Test #11:

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

input:

2
ab

output:

0

result:

ok 1 number(s): "0"

Test #12:

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

input:

2
aa

output:

2

result:

ok 1 number(s): "2"

Test #13:

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

input:

2
aa

output:

2

result:

ok 1 number(s): "2"

Test #14:

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

input:

2
ba

output:

0

result:

ok 1 number(s): "0"

Test #15:

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

input:

100
bbbabbbaababaaabaaaaabaaaaaabbabbababbbaabaababbbbaaaaaaabbabaaabbbaaabbbaaabbbababbbbaabbbbbaaabbbb

output:

41

result:

ok 1 number(s): "41"

Test #16:

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

input:

100
aabbababbbbbabaabbababaaaaabbbbbbbaaaabbbabbbbbababbababbbbabbbbbbbbbaaaabbbabaaaaabaaabababbabababb

output:

25

result:

ok 1 number(s): "25"

Test #17:

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

input:

100
bababbaaaaabbbababbaabababbaaababaabbabaaaaabaabbbbaababaaababaaaababbabbaaabaaabaababaabbbbbaabaabb

output:

42

result:

ok 1 number(s): "42"

Test #18:

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

input:

100
abbabababbbbbaabaaaabbbbbbbabbabababbaaababababaaaababaabaabbabaabaaabababbbbabbbbaabbbaababbaabbaba

output:

28

result:

ok 1 number(s): "28"

Test #19:

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

input:

100
babbbabaaabbbaabbaaaaababababbaabababbabaaaaabbbbaaababaaaaabbbaaaaabbbabaabbabaaaabaaabaaaaaaaaaabb

output:

49

result:

ok 1 number(s): "49"

Test #20:

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

input:

1000
aaabbaabaababbbbbbaabaaababaabbaabaabbabbbbbaabbbbaaabaabababaaaabaaaabbbbbbbbbbababbaaaaababbabbbbaaabaaababaaabbaababbbaabbbbbbbbbaabbaabaaabaabbbabbbaababbbaaabaabbbbaabbbbaabbbbaabaababbbabaaaabaaaabbaaaabaaabbbbaaabbbaababbbabaabbbababbabaabbabbaabbbbbabbabaabababbaaababaaabbbaabaaabbbaaab...

output:

378

result:

ok 1 number(s): "378"

Test #21:

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

input:

1000
aabaabaaabbbbabbabaaaaabaabababaabbaabbaabaaaaaaabbabbabbbabaaabaaababaaabaabbbbabbbabaabbbaaaaabaaaabbabaababaabbbababbabbbabaababaaabaababbbaabbbaabbababbaabbbaabbaabbbaabbbbabbaabaababaabbbbaabbaabbbaabbababbaabbbbababbabaaabaababbbbbaaaaababaaaaaabbbbbbaaabbabbbbaaaaabbaabbaaaaaabbbbbbabbba...

output:

431

result:

ok 1 number(s): "431"

Test #22:

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

input:

1000
abbbabbbbaaabbaaabababbbaaabbbbaaaaabbbbabaabbbbbbbbbbabaababbabbabbbbaaabbabbaaababbbbbabaababaabaaaababbaabaaababbbabbbaabbaabaaaabbbbaabaaababaabbabaaabbbaaaaabbabbbbbaaaaabbbabbaaaabbaaaaaabaabbaaababbaaabaabbabbaaabbbaaabababaaaabbaabaaaaaababaaabaabbabbababaaabaabbabaabbabbbabaabaaabababa...

output:

410

result:

ok 1 number(s): "410"

Test #23:

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

input:

1000
aabbbaaaaaaababaabababababbbbbbabbbabbbaaabbbbbabababbabbbbababbbbabbbbbaaaaaabbbaaabbabbbbaababbaabbabaaaabaaaaabbbabbaabbababababbbaaaabababbaabbabbbaaaaabaaabbaabababbbabbabbbbbbbbaaabbaaaabbaaaabbbaabbbabbababbaaabaaaaababababaaaababbbbababbaaababbabbaaaaaaaabbbaabbbaaabaabaaabbaaabbbaaaaab...

output:

363

result:

ok 1 number(s): "363"

Test #24:

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

input:

1000
bbbbabbaababaaaabbbbababbabbbabbaabaababbaabbabaabbbbbbaaababaaaaabbbaabbaaaababaabbbababaaaaabaaaaabaabbabababbaabbaababbaaaabbbaabbbaaaaaabaabbbaabaaabbabbabbabaabbaaaabaababaababbbaaaabaaabbbaaabbbabbbbaaaabaaaababaabbbbbbaabbbbaabbaaabbbbabaaabbabaabbbabbabbabbbbaabbbbbaababaaaabbbabbbababb...

output:

408

result:

ok 1 number(s): "408"

Test #25:

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

input:

1000
bbbbbabbbbaaaaaaaaaabbbbababaabaabbaaaaababaaabababbabaaabbbbaabbbabbbbaabbababbbbaabbbaabbabbbbbbbabababbabbaaababbbbabaababbbbbabbaabaaabbaaabbabbbbbaababbabbabaabbaababaaababbbabbabbaabbbbabbbbabbbbbababaaaaaaaaaabbbaabbababbbaabbaaabaaaaabbbbbabbbaaababbbabbbababbaabbbababbbbbaaababbabbabbb...

output:

360

result:

ok 1 number(s): "360"

Test #26:

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

input:

1000
abbbbababbbaababbabbbbbabaabbaaaabaaaabbbabbbabbababbaabbaaaababaabaaabbababbababbbbabbaaaabbabaababbbbbaabaabbbabbbbbaabaaababbaaababaabbbabababbabbaaababbbabbaaaaabbaaabbbbabbbaababaabbbbbbaaabaababbbbaababaaaabaabbabbbaabaaaabababaaaababbaaaaabababbabaaabbbabbbabbbaaababbaabbbabbbbbbbabbbbab...

output:

347

result:

ok 1 number(s): "347"

Test #27:

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

input:

1000
aaaaabaaaabababbbabbababababababaaaabaaabaabbbabbbaabbbbabababaaaababaabaaaaabbbaaaabbbbababbabbbaabaabbaaaababbbbbbbaaaaabbabaabaaaabbabbabaaabbbbabaababaabaaaaabbabbbaaababbabaababbabbababbbbaababaabbbbbbaabbababaaabbabaaaaabbbaaaaaaababbbbabbbabbaaaababbbabbbabbabbbabbbbbabbabbaaabbbababbaba...

output:

364

result:

ok 1 number(s): "364"

Test #28:

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

input:

1000
bbbbbaaaabbbbaabaaaaaaaaababbabbbabababbaabaabbababaabbabaaaabababaaabbbbababaabbbaabaaabaaaaabaabababbabbabaabbbabbaaaaaabbbbaababbaaaabababaabbaabbbabbaaaaaababaabbabaaaaaaabaaabaababaabbbabaabaabbbabbaaaabaaaababaababbabbaabbaabbaababaaabbbbbabbabababbbabbbaabbabbaabababaababbabbaaabbbaabaaa...

output:

366

result:

ok 1 number(s): "366"

Test #29:

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

input:

1000
aaaabaaaabaaabbabbbbaabaabaaabaabbabbaaaaaabbbbaaabbbbbabababbaaabbbbbbbbaaabaaaababbababbabbbabbabaabbaaaaabbbbbbbaabaababbbaabbaaaaaabbbbabbaaabbbbaaabaabbbbaaaaaaabbababbaaaabaaaabbbabbaaabbaaabbaabbaabbbbaabbabbbaaaabaaabbbbbaabbbbaaaabababbbabaabbbabbbaaabbbabbbbaabbbabbbabaaaabbabaaaabbbb...

output:

375

result:

ok 1 number(s): "375"

Test #30:

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

input:

10000
babababaaababbabbbbbabbaababaabaababbbabbaaaabaaababababbabbbababbaaaabbabbaabaabaababaabbabbaaabaaabaaaaabbbababaaabbbbaaabbaaaabaabbaaaaaabbbabbabbabababababaabbabbbbbbaaaaaaaaaaaabbbbbbaaaabbaaaaaaaaaaaabaabaabaaabbbbbaabaabbabaabaaabbabbabaabaabbababbabbaaaaabbabbabaaabbabaaaaaaabaaabbabab...

output:

3630

result:

ok 1 number(s): "3630"

Test #31:

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

input:

10000
baabababbaabbaaabbaabbabaabaaaababaabaabbbabbabababaabaaabaababbbabbaaaaabbabaabaaaabbaaaaabaabbabaabbabbbaababbabbbbaaabababbbbbabaaabbabbaaaabbaaababbbbabbbbaaabbabbbababaabbbabbbbaaabbaabaababbabaaabbabbbaaababbababbbabaabbabbbaaabaaaabaaabbbbabbabababbbaaabbbaaaabbbbabbbaabaabaabaabbabbaba...

output:

3880

result:

ok 1 number(s): "3880"

Test #32:

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

input:

10000
aaabbaabaaabbaaaaaabbaaabaabbbaaababbbaaabaabaababaababaabbbaabbabbbbbbabaabbaabaabbbbaaaabbbbbabbbbabbaabaaababbbbbabbaabbabbbbaaaaaaaaababbbbababaababbabbabbabbbababaabbbabbaabbbababaaaabaabbaababbbbbabaabbbbaaaaaababbbaaabbabaabaabbaabbabaaabaaaaaabbbaabbbbabaabbbaaaabbbbbbbaabbbabaaaabaaab...

output:

3736

result:

ok 1 number(s): "3736"

Test #33:

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

input:

10000
aaababaaababbababaaabbbbbbbabababaaaabbbbbbaabbbababbaaabbaabbbbaaabababbbbababbbbbbbabbbbabbbabbbabbabbaababbabaabbabbbaababaaaaaabbbbbabaabaaababaaaabbbbabaababbaaabbbababbbbaaabaaabbaaaaaaababbaabababbbbbaabbbaabaabbabaaabaababbabbababababaaabbbbbaaaaabbaababbaabbbbaabaaaaabbbabaabbabbbabbb...

output:

3740

result:

ok 1 number(s): "3740"

Test #34:

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

input:

10000
aaabbbabbaabbbbbaabbabbabbbbbbabaababbaaaabbaaaaaaaabababaaabbaabbaabbababaaaababbabbbaaabaabbbbbbabbababbaabbabababbaabaabaabaaabbbabaaaabbaabbbabbaaababbbbbabaabbbbbbbbbbabbbaabbbaaaabaaabbaabbaaaabbbaaabaaaaaaaaabbabbaabbabbabaaaaababababbabbabbbbbabababaabbaaabbaabbbaaabaaababbaaabaabbabab...

output:

3779

result:

ok 1 number(s): "3779"

Test #35:

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

input:

100000
ababaababaabbabaabaaababbbabaaababaaaaaababaaabaabbaaabaababaaababaabaabbbaaabbabbbbbbaaaabbbabaaaabbbaabbaaabbabaaaabaabbabbbabbbabaabaababababbaababaabbbaaabbbabababbabaaaaabbbbababbbbaabababbbabababaaabbbbaabbbabaaaaabaababbbbbabbbbbabbbbbaababbbbababababbabaabbaabbababbaabaaabaaaaabbbbbbb...

output:

37404

result:

ok 1 number(s): "37404"

Test #36:

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

input:

100000
bbaabbabbaabaaabbbbabbaaaabbbabbbababbababbaaabbababababbabbaaabbbabbbababaaaabbbbbbbbaaaaaaabaabaaaaaabaaabaababbaaaabababababbabbabaaababbaabbaaaabaabaabbbbaabbaabbaaaabaaabbbbabbabbabbaabbbbbbbbbababababbbaaabaaabbbbaaababbabbaaaabaaabbabbaaabaaababaaabbbaabababababbabbabbbbaaabbaaaaaaaaaa...

output:

37359

result:

ok 1 number(s): "37359"

Test #37:

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

input:

100000
aaaabbaaaaabbbaabbabbbbababbabbaababbababbbbbbbaabbbbabbaababbbaaaaabbbabbbaabaaaaababbbbaaaabbbabaababababbbaaaabaabbbabbaabaabababbbbbbbbbbbabbaaabbabbaabbbbabaaabbabbabbaabbabaaaaaabbbbbaabbaabaaaaabaababaababababbbababbbaabaaaabbbbbbbabbbabbaabbbbaababbaabbabbbabbbbbabbaabbabbabbbbaababab...

output:

37291

result:

ok 1 number(s): "37291"

Test #38:

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

input:

100000
ababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababa...

output:

0

result:

ok 1 number(s): "0"

Test #39:

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

input:

100000
ababababababababababbbababababababababababababababababababababababababababbbababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababa...

output:

712

result:

ok 1 number(s): "712"

Test #40:

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

input:

100000
abbbababbbababaaabaabbabbbabababababaaabababababababaaabaaabaaaaababababbbaaabababaaababababababababbbaaababbabbabababababababababbaabaabaaaababaabaaaabbabbbbababaaaaabbbaaabbbabbaababaaabaaaaabbbabababababaaabaaababababababababbbbbabaabbabbbabaaabbbabaaaaabbbabababaaabababaaababababababbbbbb...

output:

24034

result:

ok 1 number(s): "24034"

Test #41:

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

input:

100000
abaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaab...

output:

66666

result:

ok 1 number(s): "66666"

Test #42:

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

input:

100000
abaabaababbaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaababbaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaababbaabaabaabaabaabaabaabaabaab...

output:

66201

result:

ok 1 number(s): "66201"

Test #43:

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

input:

100000
bbaaababbaaaabaabaabbbbaaaaabaaaaabbabbbbaabaababbbabbbbabbbabbaaaabaabaabaabaababbaabaabaaaaaaabbaabbaaaabaabaabaabaabaaababaababbabbaabaababbaabbabaababbbbbbabaaabbbabbaababbabbaababbaabaababbabbaaaabbbabaabaababababbbbabbaabaabbabaabbbbaaaaaaaabaabaabaabaabaabaabbbbabbaabbabaabaaaaaaaaaaaa...

output:

51478

result:

ok 1 number(s): "51478"

Test #44:

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

input:

100000
babbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabba...

output:

0

result:

ok 1 number(s): "0"

Test #45:

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

input:

100000
babbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbaababbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbabbbbbabbabbabbabbabbabbabbabbabba...

output:

668

result:

ok 1 number(s): "668"

Test #46:

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

input:

100000
babbabbabaaababaabbababbbaababbabbabbabbaababbbbbabbaababbaababaabbabbaababbababbbabbbababbbbbabaabbbababbbbbabbaababbaaaabbbbbabbababbbabbaabbbbabbababbbabbbababbabbabaabababaababbabbabaabbabbbababbabbabbabaabbbababbbbaabbabbbbbabbabbabaabbabbabbabbabbabbabbaababbaababbabbbababbbababaaababbb...

output:

20467

result:

ok 1 number(s): "20467"