Advertisement
bibaboba12345

Untitled

Nov 8th, 2022
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. // clang-format off
  2. #define _CRT_SECURE_NO_WARNINGS
  3. #include <iostream>
  4. #include <iomanip>
  5. #include <bitset>
  6. #include <vector>
  7. #include <algorithm>
  8. #include <random>
  9. #include <map>
  10. #include <string>
  11. #include <set>
  12. #include <deque>
  13. #include <cassert>
  14.  
  15. const int N = 3e5 + 7, A = 26, C = 2, MOD = 1e9+7;
  16. using namespace std;
  17. int n;
  18.  
  19. string s;
  20.  
  21. signed main() {
  22. #ifdef _DEBUG
  23. freopen("input.txt", "r", stdin);
  24. #else
  25. std::ios::sync_with_stdio(false);
  26. cin.tie(0);
  27. #endif
  28. //freopen("input.txt", "r", stdin);
  29. cin >> s;
  30. n = s.size();
  31. long long answ = 1e18;
  32. if(n % 2 == 0){
  33. for(int i = 0; i < n; i++){
  34. long long t_ans = 0;
  35. int cnt = 0, i1 = i;
  36. for(int j = 0; j < n/2; j++){
  37. if(s[i1] == '*'){
  38. t_ans += j-cnt;
  39. cnt++;
  40. }
  41. i1++;
  42. if(i1 == n){
  43. i1 = 0;
  44. }
  45. }
  46. cnt = 0; i1 = i-1;
  47. if(i1 == -1){
  48. i1 = n-1;
  49. }
  50. for(int j = 0; j < n/2; j++){
  51. if(s[i1] == '*'){
  52. t_ans += j-cnt;
  53. cnt++;
  54. }
  55. i1--;
  56. if(i1 == -1){
  57. i1 = n-1;
  58. }
  59. }
  60. answ = min(answ, t_ans);
  61. }
  62.  
  63. }else{
  64. for(int i = 0; i < n; i++){
  65. long long t_ans = 0;
  66. int cnt = 0, i1 = i;
  67. for(int j = 0; j < n/2+1; j++){
  68. if(s[i1] == '*'){
  69. t_ans += j-cnt;
  70. cnt++;
  71. }
  72. i1++;
  73. if(i1 == n){
  74. i1 = 0;
  75. }
  76. }
  77. cnt = 0; i1 = i-1;
  78. if(i1 == -1){
  79. i1 = n-1;
  80. }
  81. for(int j = 0; j < n/2; j++){
  82. if(s[i1] == '*'){
  83. t_ans += j-cnt;
  84. cnt++;
  85. }
  86. i1--;
  87. if(i1 == -1){
  88. i1 = n-1;
  89. }
  90. }
  91. answ = min(answ, t_ans);
  92.  
  93. t_ans = 0;
  94. cnt = 0; i1 = i;
  95. for(int j = 0; j < n/2; j++){
  96. if(s[i1] == '*'){
  97. t_ans += j-cnt;
  98. cnt++;
  99. }
  100. i1++;
  101. if(i1 == n){
  102. i1 = 0;
  103. }
  104. }
  105. cnt = 0; i1 = i-1;
  106. if(i1 == -1){
  107. i1 = n-1;
  108. }
  109. for(int j = 0; j < n/2 + 1; j++){
  110. if(s[i1] == '*'){
  111. t_ans += j-cnt;
  112. cnt++;
  113. }
  114. i1--;
  115. if(i1 == -1){
  116. i1 = n-1;
  117. }
  118. }
  119. answ = min(answ, t_ans);
  120. }
  121. }
  122. cout << answ;
  123. }
  124.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement