Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <string>
- #include <stack>
- #include <set>
- #include <map>
- #define pii pair <int,int>
- #define vec vector
- #define vll vector <long long>
- using namespace std;
- using ll = long long;
- using ld = long double;
- using db = double;
- void cv(vector <int> &v){
- for (auto x: v) cout<<x<<" ";
- cout<<"\n";
- }
- void cvl(vector <ll> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvv(vector <vector <int> > &v){
- for (auto x: v) cv(x);
- cout<<"\n";
- }
- int n,why;
- vector <int> S;
- string som;
- vector <int> ans;
- vector <int> m;
- int mnk(){
- n = S.size();
- m.assign(n,0);
- int cnt=0;
- //cout<<"S\n";
- //cv(S);
- pii lr = {-1, -1};
- pii now;
- cout<<"S\n";
- cv(S);
- cout<<"m\n";
- cv(m);
- for (int i = 0; i < n;++i){
- //cout<<"i = "<<i<<"\n";
- //cout<<"S[i] = "<<S[i]<<"\n";
- //if (i%3==0)cv(S);
- int l = lr.first, r = lr.second;
- //cout<<"l r = "<<lr.first<<' '<<lr.second<<"\n";
- if (i >= l && i <= r){
- int idx = l + (r - i);
- //cout<<"idx = "<<idx<<"\n";
- m[i] = min(r - i + 1, m[idx]);
- //cout<<"m[idx] = "<<m[idx]<<"\n";
- //cout<<"r - i + 1 = "<<(r - i + 1)<<"\n";
- }
- //cout<<"m[i] = "<<m[i]<<"\n";
- while (i - m[i] >= 0 && i + m[i] < n && S[i - m[i]] == S[i + m[i]]){
- //cout<<"S[i - m[i]] = "<<S[i - m[i]]<<"\n";
- //cout<<"S[i + m[i]] = "<<S[i + m[i]]<<"\n";
- ++m[i];
- }
- //cout<<"m[i] = "<<m[i]<<"\n";
- now = {i - m[i] + 1, i + m[i] - 1};
- if (now.second > lr.second){
- lr = now;
- }
- //cout<<"\n\n";
- cv(S);
- cv(m);
- cout<<"\n";
- }
- for (int i = 0;i<som.size();++i){
- //cout<<som[i]<<" "<<'#'<<' ';
- }
- //cout<<"\n";
- //cout<<"S m\n";
- //cv(S);
- //cv(m);
- for (int i = 0; i < n;++i){
- if (S[i] != 0){
- cnt += (m[i]-1) / 2;
- }
- else cnt += m[i]/2;
- }
- cout<<"S m\n";
- //cv(S);
- //cv(m);
- for (int i=0;i<n;++i){
- //cout<<m[i]<<" ";
- }cout<<"\n";
- for (int i=0;i<n;++i){
- cout<<S[i]<<" "<<m[i]<<"\n";
- }cout<<"\n";
- return cnt;
- }
- int cher(){
- string str = som;
- ll n = str.size();
- vll d1(n), d2(n);
- ll l = 0, r = -1;
- for (ll i = 0; i < n; ++i){
- ll k;
- if (i > r) k = 1;
- else k = min(r - i + 1, d1[l + r - i]);
- while (i + k < n && i - k >= 0 && str[i + k] == str[i - k])
- k++;
- d1[i] = k;
- if ((i + k - 1) > r){
- l = i - k + 1;
- r = i + k - 1;
- }
- }
- l = 0, r = -1;
- for (ll i = 0; i < n; ++i){
- ll k;
- if (i > r) k = 0;
- else k = min(r - i + 1, d2[l + r - i + 1]);
- while (i + k < n && i - k - 1 >= 0 && str[i + k] == str[i - k - 1])
- k++;
- d2[i] = k;
- if ((i + k - 1) > r){
- l = i - k;
- r = i + k - 1;
- }
- }
- ll res = 0;
- for (ll i = 0; i < n; ++i)
- res += d1[i] + d2[i];
- res -= str.size();
- return res;
- }
- string rndS(){
- string res = "";
- int sz = rand() % 30 + 10;
- string alp = "abcdefghijklmnopqrstuvwxyz";
- for (int i = 0;i < sz;++i){
- int id = rand() % alp.size();
- res += alp[id];
- }
- return res;
- }
- int main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- //cin>>n>>why;
- /*S = {0};
- for (int i=0;i<n;++i) {
- int x;
- cin>>x;
- S.push_back(x);
- S.push_back(0);
- }
- mnk();
- sort(ans.begin(), ans.end());
- //cout<<"ans\n";
- cv(ans);*/
- //int x = 'a' - 96;
- //cout<<x<<"\n";
- //cin>>som;
- /*S = {-100};
- for (int i = 0;i<som.size();++i){
- int d = som[i] - 96;
- // cout<<"i = "<<i<<"\n";
- //cout<<"som[i] = "<<som[i]<<"\n";
- //cout<<"d = "<<d<<"\n\n";
- S.push_back(d);
- S.push_back(-100);
- }*/
- while (1){
- som = rndS();
- //cout<<som<<"\n";
- S = {0};
- for (int i = 0;i<som.size();++i){
- int d = som[i] - 96;
- // cout<<"i = "<<i<<"\n";
- //cout<<"som[i] = "<<som[i]<<"\n";
- //cout<<"d = "<<d<<"\n\n";
- S.push_back(d);
- S.push_back(0);
- }
- int monak = mnk();
- int his = cher();
- if (monak != his){
- cout<<som<<"\n";
- cout<<"my = "<<monak<<"\n";
- cout<<"his = "<<his<<"\n";
- break;
- }
- }
- //cout<<"S\n";
- //cv(S);
- //mnk();
- //cout<<cnt;
- }
- /*
- 6 2
- 1 1 2 2 1 1
- abcbaceedeeakaee
- xggbwkfnqdux
- my = 2
- his = 1
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement