이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define pb push_back
#define ln '\n'
#define int long long
bool chmin(int &x, int y){
bool flag = false;
if ( x > y ){
x = y; flag |= true;
}
return flag;
}
bool chmax(int &x, int y){
bool flag = false;
if ( x < y ){
x = y; flag |= true;
}
return flag;
}
struct Hash{
const int Mod = 1e9 + 7, P = 29;
int n;
vector <int> p, pw;
Hash(string s) : n((int)s.size()), p(n + 1), pw(n + 1, 1) {
for ( int i = 0; i < n; i++ ){
pw[i + 1] = pw[i] * P % Mod;
p[i + 1] = (p[i] * P + (s[i] - 'a' + 1)) % Mod;
}
}
int get(int l, int r){
int v = p[r + 1] - (p[l] * pw[r - l + 1]) % Mod;
return v < 0 ? Mod + v : v;
}
};
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
string s; cin >> s;
int n = (int)s.size();
map <int,int> mp;
Hash u(s);
for ( int i = 0; i < n; i++ ){
string c;
for ( int j = i; j < n; j++ ){
mp[u.get(i, j)]++;
}
}
int Mx = 0;
for ( int i = 0; i < n; i++ ){
chmax(Mx, mp[u.get(i, i)]);
for ( int j = i - 1; j >= 0; j-- ){
int l = j, r = (i - j) + i;
if ( r >= n or s[l] != s[r] ) break;
chmax(Mx, mp[u.get(l, r)] * (r - l + 1));
}
if ( i + 1 == n or s[i + 1] != s[i] ) continue;
chmax(Mx, mp[u.get(i, i+1)] * 2);
for ( int j = i - 1; j >= 0; j-- ){
int l = j, r = (i - j) + (i + 1);
if ( r >= n or s[j] != s[r] ) break;
chmax(Mx, mp[u.get(l, r)] * (r - l + 1));
}
}
cout << Mx;
cout << '\n';
}
# | 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... |