-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path1971D Binary Cut.cpp
71 lines (66 loc) · 1.48 KB
/
1971D Binary Cut.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
Author : MishkatIT
Created : Friday 10-05-2024 20:41:43
*/
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif
using ll = long long;
using ld = long double;
const ll mod = 1e9 + 7;
const ll N = 2e5 + 10;
const ll inf = 1e9;
const ll linf = 1e18;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int tc;
cin >> tc;
while (tc--) {
string str;
cin >> str;
int n = str.size();
int mx = 1;
int s = n, e = n;
int ans = 0;
for (int i = 0; i < n; i++) {
int temp = 1;
int j = i;
int cnt = 0;
while (j + 1 < n && str[j] <= str[j + 1]) {
cnt += (str[j] < str[j + 1]);
j++;
temp++;
if (temp > mx && cnt) {
ans = 1;
mx = temp;
s = i, e = j;
}
}
i = j;
}
for (int i = 0; i < s; i++) {
ans++;
int j = i;
while (j + 1 < s && str[j] == str[j + 1]) {
j++;
}
i = j;
}
// debug(ans);
for (int i = e + 1; i < n; i++) {
ans++;
int j = i;
while (j + 1 < n && str[j] == str[j + 1]) {
j++;
}
i = j;
}
cout << ans << '\n';
}
return 0;
}