This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
#define rrep(i,a,b) for(int i=int(a);i>int(b); i--);
#define all(v) v.begin(),v.end()
#define trav(a,v) for(auto&a:v)
using namespace std;
typedef long long ll;
const ll inf = 1e15;
vector<vector<ll>> dp(1001, vector<ll>(1001, -1));
bool solve(ll l, ll r, string& s) {
if (l == r)return 1;
else if (l + 1 == r)return s[l] == s[r];
return dp[l][r]=(s[l] == s[r] && solve(l +1, r - 1,s));
}
int main()
{
cin.sync_with_stdio(false);
string s1, s2;
cin >> s1;
ll ans = 0;
map<string, ll> mp;
rep(i, 0, s1.size()) {
string curs = "";
rep(j, i, s1.size()) {
curs += s1[j];
if (solve(i, j, s1)) {
mp[curs]++;
}
}
}
trav(a, mp) {
ll val = a.first.size() * a.second;
ans = max(ans, val);
}
cout << ans;
return 0;
}
Compilation message (stderr)
palindrome.cpp: In function 'bool solve(ll, ll, std::string&)':
palindrome.cpp:18:17: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
18 | return dp[l][r]=(s[l] == s[r] && solve(l +1, r - 1,s));
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |