#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int m_INF = -1e9+7;
bool palindrom(string s){
reverse(s.begin(),s.end());
string z = s ;
reverse(s.begin(),s.end());
if(z == s){
return true;
}
else{
return false;
}
}
ll find_say_string(string s , string q)
{
ll say = 0 ;
for(ll i = 0;i < s.size();i++){
string z = s.substr(i,i+q.size());
if(z == q)
{
say++;
}
}
return say ;
}
void find_max_palindrom_on_string(string s)
{
ll l = 0 , r = s.size()-1 ;
vector < string > palindroms ;
vector < char > q ;
if(palindrom(s)){
palindroms.push_back(s);
}
for(ll i = 0;i < s.size();i++){
q.push_back(s[i]);
}
while(r > 0)
{
string z = s.substr(l,r);
if(palindrom(z) && z.size() != 1)
{
palindroms.push_back(z);
}
l++;
if(l == r)
{
l = 0 ;
r--;
}
}
sort(palindroms.begin(),palindroms.end());
for(ll i = 0;i < palindroms.size();i++){
if(palindroms[i] == palindroms[i+1]){
palindroms.erase(palindroms.begin() + i);
}
}
sort(q.begin(),q.end());
///////////////////////////////////////////////////////////////////////////////
int maks = m_INF ;
for(ll i = 0;i < palindroms.size();i++)
{
string t = palindroms[i];
maks = max(maks,int(t.size())*(int((find_say_string(s,t)))));
}
for(ll i = 0;i < q.size();i++)
{
int say = 0 ;
char c = q[i] ;
for(ll j = 0;j < s.size();j++)
{
if(s[j] == c){
say++;
}
}
maks = max(maks,say);
}
cout << maks << endl ;
}
signed main()
{
string s ;
cin >> s ;
find_max_palindrom_on_string(s);
}
Compilation message
palindrome.cpp: In function 'long long int find_say_string(std::string, std::string)':
palindrome.cpp:26:20: 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]
26 | for(ll i = 0;i < s.size();i++){
| ~~^~~~~~~~~~
palindrome.cpp: In function 'void find_max_palindrom_on_string(std::string)':
palindrome.cpp:50:20: 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]
50 | for(ll i = 0;i < s.size();i++){
| ~~^~~~~~~~~~
palindrome.cpp:75:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
75 | for(ll i = 0;i < palindroms.size();i++){
| ~~^~~~~~~~~~~~~~~~~~~
palindrome.cpp:87:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
87 | for(ll i = 0;i < palindroms.size();i++)
| ~~^~~~~~~~~~~~~~~~~~~
palindrome.cpp:94:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
94 | for(ll i = 0;i < q.size();i++)
| ~~^~~~~~~~~~
palindrome.cpp:100:24: 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]
100 | for(ll j = 0;j < s.size();j++)
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
418 ms |
131072 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
420 ms |
131072 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
490 ms |
131072 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
538 ms |
131072 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |