Advertisement
Korotkodul

ЗОШ полиндром debug

Jan 13th, 2022 (edited)
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.91 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <queue>
  5. #include <algorithm>
  6. #include <string>
  7. #include <stack>
  8. #include <set>
  9. #include <map>
  10. #define pii pair <int,int>
  11. #define vec vector
  12. #define vll vector <long long>
  13. using namespace std;
  14. using ll = long long;
  15. using ld = long double;
  16. using db = double;
  17. void cv(vector <int> &v){
  18. for (auto x: v) cout<<x<<" ";
  19. cout<<"\n";
  20. }
  21.  
  22. void cvl(vector <ll> &v){
  23. for (auto x: v) cout<<x<<' ';
  24. cout<<"\n";
  25. }
  26.  
  27.  
  28. void cvv(vector <vector <int> > &v){
  29. for (auto x: v) cv(x);
  30. cout<<"\n";
  31. }
  32.  
  33. int n,why;
  34.  
  35. vector <int> S;
  36.  
  37. string som;
  38.  
  39. vector <int> ans;
  40.  
  41. vector <int> m;
  42.  
  43.  
  44.  
  45. int mnk(){
  46. n = S.size();
  47. m.assign(n,0);
  48. int cnt=0;
  49. //cout<<"S\n";
  50. //cv(S);
  51. pii lr = {-1, -1};
  52. pii now;
  53. cout<<"S\n";
  54. cv(S);
  55. cout<<"m\n";
  56. cv(m);
  57. for (int i = 0; i < n;++i){
  58. //cout<<"i = "<<i<<"\n";
  59. //cout<<"S[i] = "<<S[i]<<"\n";
  60. //if (i%3==0)cv(S);
  61. int l = lr.first, r = lr.second;
  62. //cout<<"l r = "<<lr.first<<' '<<lr.second<<"\n";
  63. if (i >= l && i <= r){
  64. int idx = l + (r - i);
  65. //cout<<"idx = "<<idx<<"\n";
  66. m[i] = min(r - i + 1, m[idx]);
  67. //cout<<"m[idx] = "<<m[idx]<<"\n";
  68. //cout<<"r - i + 1 = "<<(r - i + 1)<<"\n";
  69. }
  70. //cout<<"m[i] = "<<m[i]<<"\n";
  71. while (i - m[i] >= 0 && i + m[i] < n && S[i - m[i]] == S[i + m[i]]){
  72. //cout<<"S[i - m[i]] = "<<S[i - m[i]]<<"\n";
  73. //cout<<"S[i + m[i]] = "<<S[i + m[i]]<<"\n";
  74. ++m[i];
  75. }
  76. //cout<<"m[i] = "<<m[i]<<"\n";
  77. now = {i - m[i] + 1, i + m[i] - 1};
  78. if (now.second > lr.second){
  79. lr = now;
  80. }
  81. //cout<<"\n\n";
  82. cv(S);
  83. cv(m);
  84. cout<<"\n";
  85. }
  86. for (int i = 0;i<som.size();++i){
  87. //cout<<som[i]<<" "<<'#'<<' ';
  88. }
  89. //cout<<"\n";
  90. //cout<<"S m\n";
  91. //cv(S);
  92. //cv(m);
  93. for (int i = 0; i < n;++i){
  94. if (S[i] != 0){
  95. cnt += (m[i]-1) / 2;
  96. }
  97. else cnt += m[i]/2;
  98. }
  99. cout<<"S m\n";
  100. //cv(S);
  101. //cv(m);
  102. for (int i=0;i<n;++i){
  103. //cout<<m[i]<<" ";
  104. }cout<<"\n";
  105. for (int i=0;i<n;++i){
  106. cout<<S[i]<<" "<<m[i]<<"\n";
  107. }cout<<"\n";
  108. return cnt;
  109. }
  110.  
  111.  
  112. int cher(){
  113. string str = som;
  114. ll n = str.size();
  115.  
  116. vll d1(n), d2(n);
  117.  
  118.  
  119. ll l = 0, r = -1;
  120. for (ll i = 0; i < n; ++i){
  121. ll k;
  122.  
  123. if (i > r) k = 1;
  124. else k = min(r - i + 1, d1[l + r - i]);
  125.  
  126. while (i + k < n && i - k >= 0 && str[i + k] == str[i - k])
  127. k++;
  128.  
  129. d1[i] = k;
  130.  
  131. if ((i + k - 1) > r){
  132. l = i - k + 1;
  133. r = i + k - 1;
  134. }
  135. }
  136.  
  137.  
  138. l = 0, r = -1;
  139. for (ll i = 0; i < n; ++i){
  140. ll k;
  141.  
  142. if (i > r) k = 0;
  143. else k = min(r - i + 1, d2[l + r - i + 1]);
  144.  
  145. while (i + k < n && i - k - 1 >= 0 && str[i + k] == str[i - k - 1])
  146. k++;
  147.  
  148. d2[i] = k;
  149.  
  150. if ((i + k - 1) > r){
  151. l = i - k;
  152. r = i + k - 1;
  153. }
  154. }
  155.  
  156.  
  157. ll res = 0;
  158. for (ll i = 0; i < n; ++i)
  159. res += d1[i] + d2[i];
  160.  
  161. res -= str.size();
  162. return res;
  163. }
  164.  
  165.  
  166. string rndS(){
  167. string res = "";
  168. int sz = rand() % 30 + 10;
  169. string alp = "abcdefghijklmnopqrstuvwxyz";
  170. for (int i = 0;i < sz;++i){
  171. int id = rand() % alp.size();
  172. res += alp[id];
  173. }
  174. return res;
  175. }
  176.  
  177. int main()
  178. {
  179. ios::sync_with_stdio(0);
  180. cin.tie(0);
  181. cout.tie(0);
  182. //cin>>n>>why;
  183. /*S = {0};
  184. for (int i=0;i<n;++i) {
  185. int x;
  186. cin>>x;
  187. S.push_back(x);
  188. S.push_back(0);
  189. }
  190. mnk();
  191. sort(ans.begin(), ans.end());
  192. //cout<<"ans\n";
  193. cv(ans);*/
  194. //int x = 'a' - 96;
  195. //cout<<x<<"\n";
  196. //cin>>som;
  197. /*S = {-100};
  198. for (int i = 0;i<som.size();++i){
  199. int d = som[i] - 96;
  200. // cout<<"i = "<<i<<"\n";
  201. //cout<<"som[i] = "<<som[i]<<"\n";
  202. //cout<<"d = "<<d<<"\n\n";
  203. S.push_back(d);
  204. S.push_back(-100);
  205. }*/
  206. while (1){
  207. som = rndS();
  208. //cout<<som<<"\n";
  209. S = {0};
  210. for (int i = 0;i<som.size();++i){
  211. int d = som[i] - 96;
  212. // cout<<"i = "<<i<<"\n";
  213. //cout<<"som[i] = "<<som[i]<<"\n";
  214. //cout<<"d = "<<d<<"\n\n";
  215. S.push_back(d);
  216. S.push_back(0);
  217. }
  218. int monak = mnk();
  219. int his = cher();
  220. if (monak != his){
  221. cout<<som<<"\n";
  222. cout<<"my = "<<monak<<"\n";
  223. cout<<"his = "<<his<<"\n";
  224. break;
  225. }
  226. }
  227. //cout<<"S\n";
  228. //cv(S);
  229. //mnk();
  230. //cout<<cnt;
  231. }
  232. /*
  233. 6 2
  234. 1 1 2 2 1 1
  235.  
  236. abcbaceedeeakaee
  237.  
  238.  
  239. xggbwkfnqdux
  240. my = 2
  241. his = 1
  242. */
  243.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement