Submission #1112785

#TimeUsernameProblemLanguageResultExecution timeMemory
1112785groshiPalindromes (APIO14_palindrome)C++17
100 / 100
700 ms72336 KiB
#include <bits/stdc++.h> #define int long long using namespace std; int maxx=1e9; int pierw[2]={2137,601}; int mod[2]={maxx+7,maxx+9}; int potegi[400000][2]; int hasze[400000][2]; int dl[400000]; bool odw[400000]; int licze[400000]; int essa[800000]; int ktory=1; map<pair<int,int>,int> mapka; vector<int> Q[400000]; pair<int,int> licz(int x,int y) { int hasz1=(hasze[y][0]-hasze[x-1][0]*potegi[y-x+1][0]+mod[0]*mod[0])%mod[0]; int hasz2=(hasze[y][1]-hasze[x-1][1]*potegi[y-x+1][1]+mod[1]*mod[1])%mod[1]; return {hasz1,hasz2}; } int szukaj(pair<int,int> hasze,int x,int y) { if(mapka.find(hasze)!=mapka.end()) return mapka[hasze]; mapka[hasze]=ktory; dl[ktory]=y-x+1; ktory++; return ktory-1; } int dfs(int x) { if(odw[x]) return licze[x]; odw[x]=1; for(int i=0;i<Q[x].size();i++) licze[x]+=dfs(Q[x][i]); return licze[x]; } void reku(int x,int y) { pair<int,int> hasz=licz(x,y); int ktory=szukaj(hasz,x,y); if(odw[ktory] || x+1>y-1) return; odw[ktory]=1; pair<int,int> hasz2=licz(x+1,y-1); int ktory2=szukaj(hasz2,x+1,y-1); Q[ktory2].push_back(ktory); reku(x+1,y-1); } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); string s; cin>>s; potegi[0][0]=1; potegi[0][1]=1; for(int i=1;i<=s.length();i++) for(int j=0;j<2;j++) potegi[i][j]=(potegi[i-1][j]*pierw[j])%mod[j]; for(int i=0;i<s.length();i++) for(int j=0;j<2;j++) { if(i!=0) hasze[i][j]=(hasze[i-1][j]*pierw[j]+(s[i]-'a'+1))%mod[j]; else hasze[i][j]=(s[i]-'a'+1); } vector<char> pomoc; pomoc.push_back(s[0]); for(int i=1;i<s.length();i++) pomoc.push_back('.'),pomoc.push_back(s[i]); int n=s.length(); int r=-1; int k=-1; for(int i=0;i<2*n-1;i++) { if(i<=r) essa[i]=min(essa[2*k-i],r-i); while(i-essa[i]-1>=0 && i+essa[i]+1<2*n-1 && pomoc[i-essa[i]-1]==pomoc[i+essa[i]+1]) essa[i]++; if(r<i+essa[i]) r=i+essa[i],k=i; int dl,x,y; if(i%2==1) { dl=(essa[i]+1)/2; x=i/2-dl+1; y=i/2+dl; } else{ dl=essa[i]/2; x=i/2-dl; y=i/2+dl; } if(x>y) continue; pair<int,int> hasz=licz(x,y); licze[szukaj(hasz,x,y)]++; reku(x,y); } for(int i=0;i<=ktory;i++) odw[i]=0; int wynik=0; for(int i=1;i<ktory;i++) wynik=max(wynik,dl[i]*dfs(i)); cout<<wynik; return 0; }

Compilation message (stderr)

palindrome.cpp: In function 'long long int dfs(long long int)':
palindrome.cpp:36:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     for(int i=0;i<Q[x].size();i++)
      |                 ~^~~~~~~~~~~~
palindrome.cpp: In function 'int32_t main()':
palindrome.cpp:61:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |     for(int i=1;i<=s.length();i++)
      |                 ~^~~~~~~~~~~~
palindrome.cpp:64:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |     for(int i=0;i<s.length();i++)
      |                 ~^~~~~~~~~~~
palindrome.cpp:73:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |     for(int i=1;i<s.length();i++)
      |                 ~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...