-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1729_C.cpp
More file actions
75 lines (71 loc) · 1.76 KB
/
1729_C.cpp
File metadata and controls
75 lines (71 loc) · 1.76 KB
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
72
73
74
75
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve(){
string str; cin >> str;
int N = str.size();
int result = 0;
char last = str[N - 1];
char first = str[0];
pair<int,int> arr[N];
for (int i = 0; i < N; i++) {
arr[i] = {str[i] - 'a', i};
}
sort(arr,arr+N);
if (first <= last) {
int start = 0;
for (int i = 0; i < N; i++) {
if (arr[i].first == first - 'a') {
start = i;
break;
}
}
int end = 0;
for (int i = N-1; i >= 0; i--) {
if (arr[i].first == last - 'a') {
end = i;
break;
}
}
cout << last - first << ' ' << end - start + 1 << '\n';
while (start <= end) {
auto [a,b] = arr[start];
cout << b+1 << ' ';
start++;
}
} else {
int start = 0;
for (int i = N-1; i >= 0; i--) {
if (arr[i].first == first - 'a') {
start = i;
break;
}
}
int end = 0;
for (int i = 0; i < N; i++) {
if (arr[i].first == last - 'a') {
end = i;
break;
}
}
cout << first - last << ' ' << start - end + 1 << '\n';
cout << 1 << ' ';
while (start >= end) {
auto [a,b] = arr[start];
if (b != N-1 && b != 0) cout << b+1 << ' ';
start--;
}
cout << N << ' ';
}
}
int main()
{
cin.tie(0)->sync_with_stdio(false);
int T = 1;
cin >> T;
while (T--) {
solve();
cout << '\n';
}
return 0;
}