Advertisement
NHumme

Untitled

Apr 9th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <algorithm>
  4. #include <cmath>
  5. #include <vector>
  6. #include <string>
  7. #include <set>
  8. #include <stack>
  9. #include <queue>
  10. #include <deque>
  11. using namespace std;
  12.  
  13.  
  14.  
  15. #define TASK "negcycle"
  16.  
  17.  
  18.  
  19. string s;
  20.  
  21. char minb_p[200000], minb_s[200000];
  22.  
  23. int nom_p[200000], nom_s[200000], mind, maxk, n, idx;
  24.  
  25.  
  26.  
  27. int main() {
  28.  
  29.  
  30.  
  31. #ifdef _DEBUG
  32.  
  33. freopen("debug.in", "r", stdin);
  34.  
  35. freopen("debug.out", "w", stdout);
  36.  
  37. #else
  38.  
  39. //freopen(TASK".in", "r", stdin);
  40.  
  41. //freopen(TASK".out", "w", stdout);
  42.  
  43. //freopen("input.txt", "r", stdin);
  44.  
  45. //freopen("output.txt", "w", stdout);
  46.  
  47. #endif // _DEBUG
  48.  
  49.  
  50.  
  51. ios_base::sync_with_stdio(0);
  52.  
  53. cin.tie(0);
  54.  
  55. cout.tie(0);
  56.  
  57. cout.precision(6);
  58.  
  59.  
  60.  
  61.  
  62.  
  63. cin >> s;
  64.  
  65. n = s.size();
  66.  
  67. minb_p[0] = s[0];
  68.  
  69. nom_p[0] = 0;
  70.  
  71. minb_s[n - 1] = s[n - 1];
  72.  
  73. nom_s[n - 1] = n - 1;
  74.  
  75. for (int i = 1; i<n; i++)
  76.  
  77. {
  78.  
  79. if (s[i] <= minb_p[i - 1])
  80.  
  81. {
  82.  
  83. minb_p[i] = s[i];
  84.  
  85. nom_p[i] = i;
  86.  
  87. }
  88.  
  89. else
  90.  
  91. {
  92.  
  93. minb_p[i] = minb_p[i - 1];
  94.  
  95. nom_p[i] = nom_p[i - 1];
  96.  
  97. }
  98.  
  99. }
  100.  
  101. for (int i = n - 2; i >= 0; i--)
  102.  
  103. {
  104.  
  105. if (s[i] <= minb_s[i + 1])
  106.  
  107. {
  108.  
  109. minb_s[i] = s[i];
  110.  
  111. nom_s[i] = i;
  112.  
  113. }
  114.  
  115. else
  116.  
  117. {
  118.  
  119. minb_s[i] = minb_s[i + 1];
  120.  
  121. nom_s[i] = nom_s[i + 1];
  122.  
  123. }
  124.  
  125. }
  126.  
  127. maxk = 0;
  128.  
  129. mind = 1000000;
  130.  
  131. for (int i = n - 1; i >= 0; i--)
  132.  
  133. {
  134.  
  135. if (s[i] - minb_p[i]==maxk && mind > i - nom_p[i] + 1 || s[i] - minb_p[i] > maxk)
  136.  
  137. {
  138.  
  139. idx = nom_p[i];
  140.  
  141. mind = i - nom_p[i] + 1;
  142.  
  143. maxk = s[i] - minb_p[i];
  144.  
  145. }
  146.  
  147. if (s[i] - minb_s[i] == maxk && mind > nom_s[i] - i + 1 || s[i] - minb_s[i] > maxk)
  148.  
  149. {
  150.  
  151. idx = i;
  152.  
  153. mind = nom_s[i] - i + 1;
  154.  
  155. maxk = s[i] - minb_s[i];
  156.  
  157. }
  158.  
  159.  
  160.  
  161. }
  162.  
  163. cout << s.substr(idx, mind);
  164.  
  165.  
  166.  
  167. return 0;
  168.  
  169. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement