이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define all(a) a.begin(), a.end()
typedef long long ll;
typedef pair<int, int> ii;
const int N = 10000 + 5;
const int mod = 1e9 + 7;
bool dp[N][N];
string s;
int n, P[N], H[N];
unordered_map<int, int> mp;
int Hash(int l, int r)
{
return (H[r] - 1ll * H[l - 1] * P[r - l + 1] + 1ll * mod * mod) % mod;
}
void build()
{
for(int i = 1; i <= n; i++)
H[i] = (1ll * H[i - 1] * P[1] + (s[i] - 'a' + 1)) % mod;
}
void solve()
{
cin >> s;
n = s.size();
s = " " + s;
P[1] = 431;
for(int i = 2; i <= n; i++)
P[i] = 1ll * P[i - 1] * P[1] % mod;
build();
for(int j = 1; j <= n; j++)
for(int i = j; i >= 1; i--) if(s[i] == s[j])
dp[i][j] = (i == j || i + 1 == j || dp[i + 1][j - 1]);
int res = 0;
for(int i = 1; i <= n; i++)
for(int j = i; j <= n; j++)
if(dp[i][j]) res = max(res, mp[Hash(i, j)] += (j - i + 1));
cout << res;
}
signed main()
{
cin.tie(0)->sync_with_stdio(0);
int t = 1;
// cin >> t;
while(t--) solve();
return 0;
}
# | 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... |