이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <bitset>
#include <cmath>
#include <queue>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
struct segment{int l, r, id;
int size(){return r-l+1;}};
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define ent "\n"
const int maxn = 25e4 + 100;
const ll INF = (1ll<<61);
const int MOD = 1e9 + 7;
const int inf = (1<<30);
const int maxl = 20;
const int P = 31;
int n;
string s;
vector<int> g[maxn];
ll pref[maxn];
ll suf[maxn];
ll pw[maxn];
int d[maxn];
int ok(int l, int r){
int num1 = pref[r] - pref[l-1] * pw[r - l + 1] % MOD;
int num2 = suf[l] - suf[r+1] * pw[r - l + 1] % MOD;
if(num1 < 0) num1 += MOD;
if(num2 < 0) num2 += MOD;
return num1 == num2;
}
void test(){
cin >> s;
n = s.size();
s = '#' + s;
pw[0] = 1;
for(int i = 1; i <= n; i++){
pref[i] = (pref[i-1] * P + s[i] - 'a' + 1) % MOD;
pw[i] = (pw[i-1] * P) % MOD;
}
for(int i = n; i > 0; i--){
suf[i] = (suf[i + 1] * P + s[i] - 'a' + 1) % MOD;
}
for(int l = 1; l <= n; l++){
for(int r = l; r <= n; r++){
if(ok(l, r)){
g[r - l + 1].push_back((pref[r] - pref[l-1] * pw[r - l + 1] % MOD + MOD) % MOD);
}
}
}
ll ans = 0;
for(int i = 1; i <= n; i++){
sort(g[i].begin(), g[i].end());
int cnt = 0;
for(int j = 0; j < g[i].size(); j++){
if(j == 0 || g[i][j] != g[i][j-1]) cnt = 0;
cnt++;
ans = max(ans, 1ll * cnt * i);
}
}
cout << ans;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int t; t = 1;
while(t--) test();
}
컴파일 시 표준 에러 (stderr) 메시지
palindrome.cpp: In function 'void test()':
palindrome.cpp:64:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
64 | for(int j = 0; j < g[i].size(); j++){
| ~~^~~~~~~~~~~~~
# | 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... |