#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()-q.size();i++){
string z = "";
for(ll j = i;j < i + q.size();j++)
{
z += s[j];
}
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()-q.size();i++){
| ~~^~~~~~~~~~~~~~~~~~~~
palindrome.cpp:29:24: warning: comparison of integer expressions of different signedness: 'long long int' and 'long long unsigned int' [-Wsign-compare]
29 | for(ll j = i;j < i + q.size();j++)
| ~~^~~~~~~~~~~~~~
palindrome.cpp: In function 'void find_max_palindrom_on_string(std::string)':
palindrome.cpp:55: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]
55 | for(ll i = 0;i < s.size();i++){
| ~~^~~~~~~~~~
palindrome.cpp:80: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]
80 | for(ll i = 0;i < palindroms.size();i++){
| ~~^~~~~~~~~~~~~~~~~~~
palindrome.cpp:92: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]
92 | for(ll i = 0;i < palindroms.size();i++)
| ~~^~~~~~~~~~~~~~~~~~~
palindrome.cpp:99:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
99 | for(ll i = 0;i < q.size();i++)
| ~~^~~~~~~~~~
palindrome.cpp:105: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]
105 | for(ll j = 0;j < s.size();j++)
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
432 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
422 ms |
131072 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
426 ms |
131072 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
484 ms |
131072 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
537 ms |
131072 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |