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
- 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";
- }
- void cvc(vector <char> v){
- for (char x: v) cout<<x<<' ';
- cout<<"\n";
- }
- vector <char> S;
- int n;
- vector <int> m;
- vector <int> clr;
- //clear m for clc pol-s
- int cnt=0;
- string som;
- void mnk(){
- //cout<<"S\n";
- //cvc(S);
- n = S.size();
- m.resize(n, 0);
- clr.resize(n);
- pii lr = {-1, -1}, now;
- for (int i = 0;i <n;++i){
- int l = lr.first, r = lr.second;
- if (i >= l && i <= r){
- int idx = l + (r - i);
- m[i] = min(r - i + 1, m[idx]);
- }
- while (i - m[i] >= 0 && i + m[i] < n && S[i - m[i]] == S[i + m[i]]){
- ++m[i];
- }
- now = {i - m[i] + 1, i + m[i] - 1};
- if (now.second > lr.second){
- lr = now;
- }
- }
- for (int i=0;i<n;++i){
- if (S[i] != '@') m[i]--;
- clr[i] = m[i] / 2;
- }
- for (int i = 0;i<n;++i) {
- cnt += clr[i];
- }
- }
- int check=0;
- void stp(){//stupid
- som = '@' + som + '@';
- n = som.size();
- //cout<<"som n = "<<som<<' '<<n<<"\n";
- //cout<<"check = "<<check<<"\n";
- //сначала считаем четные полиндромы
- int id1 , id2 ;
- for (int i = 1; i < n-1; ++i){
- id1 = i - 1;
- id2 = i + 1;
- //cout<<"ONE\n";
- while (id1 >= 0 && id2 < n && som[id1] == som[id2]){
- //cout<<"id1 id2 = "<<id1<<' '<<id2<<"\n";
- if (som[id1] == '@' || som[id2] == '@') break;
- //cout<<"id1 id2 = "<<id1<<' '<<id2<<"\n";
- id1--;
- id2++;
- check++;
- //cout<<"+\n";
- }
- id1 = i;
- id2 = i + 1;
- //cout<<"TWO\n";
- while (id1 >=0 && id2 < n && som[id1] == som[id2]){
- if (som[id1] == '@' || som[id2] == '@') break;
- //cout<<"id1 id2 = "<<id1<<' '<<id2<<"\n";
- id1--;
- id2++;
- check++;
- //cout<<"+\n";
- }
- }
- //потом нечетные
- }
- string generateTheString(int n)
- {
- string ans="";
- // If n is odd
- if(n%2)
- {
- // Add all characters from
- // b-y
- for(int i=0;i<min(n,24);i++)
- {
- ans+=(char)('b' + i);
- }
- // Append a to fill the
- // remaining length
- if(n>24)
- {
- for(int i=0;i<(n-24);i++)
- ans+='a';
- }
- }
- // If n is even
- else
- {
- // Add all characters from
- // b-z
- for(int i=0;i<min(n,25);i++)
- {
- ans+=(char)('b' + i);
- }
- // Append a to fill the
- // remaining length
- if(n>25)
- {
- for(int i=0;i<(n-25);i++)
- ans+='a';
- }
- }
- return ans;
- }
- #include <stdio.h> /* printf, scanf, puts, NULL */
- #include <stdlib.h> /* srand, rand */
- #include <time.h>
- int main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- //cin>>som;
- do {
- int sz = rand() % 100;
- cout<<"sz = "<<sz<<"\n";
- cout<<som<<"\n";
- som = generateTheString(sz);
- S = {'@'};
- for (int i=0;i<som.size();++i){
- S.push_back(som[i]);
- S.push_back('@');
- }
- stp();
- mnk();
- } while (check == cnt);
- }
- /*
- aaaa
- cdeedcfcbcf
- abcdeedcfbfaartl
- ltlmlm
- kakaka
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement