# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
955473 | hoanganh_siuuuuuuuu | Palindromes (APIO14_palindrome) | C++17 | 1059 ms | 6672 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long
#define f(i, a, b) for(int i = a; i <= b; i++)
#define fr(i, a, b) for(int i = a; i >= b; i--)
#define pii pair <int, int>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define in insert
#define vvec vector<vector<int>>
#define fast ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
const int N = 3e5 + 5;
const int mod = 1e9 + 7;
const int base = 31;
int n, Hash[N], Pow[N];
unordered_map <int, int> mp;
string s;
int get(int i, int j)
{
return (Hash[j] - Hash[i - 1] * Pow[j - i + 1] + mod * mod) % mod;
}
void sub2()
{
int res = 0;
f(i, 1, n)
{
int t = 0;
while(i - t >= 1 && i + t <= n && s[i - t] == s[i + t])
{
int z = ++mp[get(i - t, i + t)];
// cout << get(i - t, i + t) << "\n";
//cout << i << " " << z << " " << (2 * t + 1) << "\n";
res = max(res, (2 * t + 1) * z);
t++;
}
t = 0; int j = i + 1;
while(i - t >= 1 && j + t <= n && s[i - t] == s[j + t])
{
int z = ++mp[get(i - t, j + t)];
//cout << get(i - t, j + t) << "\n";
//cout << i << " " << z << " " << (2 * t + 2) << "\n";
res = max(res, (2 * t + 2) * z);
t++;
}
}
cout << res;
}
signed main()
{
fast;
if(fopen("palindrome.in", "r"))
{
freopen("palindrome.in", "r", stdin);
freopen("palindrome.out", "w", stdout);
}
cin >> s;
n = s.size(); s = '!' + s;
Pow[0] = 1;
f(i, 1, n)
{
//a[i] = s[i] - 'a';
Hash[i] = (Hash[i - 1] * base + (s[i] - 'a' + 1)) % mod;
Pow[i] = (Pow[i - 1] * base) % mod;
}
sub2();
//int l = 0,
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |