fork download
  1. #include <algorithm>
  2. #include <iomanip>
  3. #include <iostream>
  4. #include <vector>
  5. #include <set>
  6. #include <numeric>
  7. #include <map>
  8. #include <unordered_map>
  9. using namespace std;
  10. #define all(a) a.begin(), a.end()
  11. #define ll long long
  12. #define fo(i,n) for (long long i = 0; i < n; i++)
  13. bool comp(pair<char,ll> a, pair<char,ll> b)
  14. {
  15. return (a.first < b.first);
  16. }
  17. bool comp2(pair<char,ll> a, pair<char,ll> b)
  18. {
  19. return (a.first > b.first);
  20. }
  21. int main()
  22. {
  23. ios_base::sync_with_stdio(false);
  24. cin.tie(0); cout.tie(0);
  25. ll n,m,i;
  26. ll a,b;
  27. string input;
  28. cin >> i;
  29. while (i--)
  30. {
  31. cin >> input;
  32. ll cost = 0;
  33. ll vis = 0;
  34. vector<pair<char,ll>> ans;
  35. char first = input[0];
  36. char last = input[input.size()-1];
  37. string input2 = input.substr(1,input.size()-2);
  38. for (int i = 0; i < input2.size(); i++)
  39. {
  40. if (first < last)
  41. {
  42. if (input2[i] >= first && input2[i] <= last)
  43. {
  44. ans.push_back(make_pair(input2[i],i+2));
  45. vis++;
  46. }
  47. }
  48. else if (first > last)
  49. {
  50. if (input2[i] <= first && input2[i] >= last)
  51. {
  52. ans.push_back(make_pair(input2[i],i+2));
  53. vis++;
  54. }
  55. }
  56. else
  57. {
  58. if (input2[i] == first)
  59. {
  60. ans.push_back(make_pair(input2[i],i+2));
  61. vis++;
  62. }
  63. }
  64. }
  65. if (first < last)
  66. {
  67. sort(all(ans),comp);
  68. }
  69. if (first > last)
  70. {
  71. sort(all(ans),comp2);
  72. }
  73. if (input.size() == 2)
  74. {
  75. cout << abs(last - first) << ' ' << 2 << endl;
  76. cout << 1 << ' ' << 2;
  77. }
  78. else
  79. {
  80. cout << abs(last - first) << ' ' << vis+2 << '\n';
  81. cout << 1 << ' ';
  82. for (auto a: ans)
  83. {
  84. cout << a.second << ' ';
  85. }
  86. cout << input.size();
  87. }
  88. cout << '\n';
  89. }
  90. }
Success #stdin #stdout 0.01s 5284KB
stdin
6
logic
codeforces
bca
aaaaaaaaaaa
adbaadabad
to
stdout
9 4
1 4 3 5
16 10
1 8 3 4 9 5 2 6 7 10
1 2
1 3
0 11
1 2 3 4 5 6 7 8 9 10 11
3 10
1 4 5 7 9 3 8 2 6 10
5 2
1 2