이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>*/
#define pb push_back
#define mp make_pair
#define sz(s) ((int)(s.size()))
#define all(s) s.begin(), s.end()
#define rep(i, a, n) for (int i = a; i <= n; ++i)
#define per(i, n, a) for (int i = n; i >= a; --i)
#define onlycin ios_base::sync_with_stdio(false); cin.tie(0)
using namespace std;
// using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
/*typedef tree<
pair < int, int >,
null_type,
less< pair < int, int > >,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;*/
// find_by_order() order_of_key()
const int MAXN = (int)1e5+228;
const char nxtl = '\n';
const int mod = (int)1e9+7;
const double eps = (double)1e-7;
template<typename T> inline bool updmin(T &a, const T &b) {return a > b ? a = b, 1 : 0;}
template<typename T> inline bool updmax(T &a, const T &b) {return a < b ? a = b, 1 : 0;}
int n, suff[MAXN], c[MAXN], nc[MAXN], tmp[MAXN], cnt[MAXN], timer;
char s[MAXN];
int lcp[MAXN], pos[MAXN];
inline void calc() {
rep(i, 1, max(n, 256)) cnt[i] += cnt[i - 1];
per(i, max(n, 256), 0) cnt[i + 1] = cnt[i];
cnt[0] = 0;
}
inline void SA() {
memset(cnt, 0, sizeof cnt);
s[n++] = (char)0;
rep(i, 0, n - 1) cnt[s[i]]++;
calc();
rep(i, 0, n - 1) {
suff[cnt[s[i]]++] = i;
}
c[suff[0]] = 0;
rep(i, 1, n - 1) {
if(s[suff[i]] == s[suff[i - 1]]) c[suff[i]] = c[suff[i - 1]];
else c[suff[i]] = c[suff[i - 1]] + 1;
}
for(int len = 1; len <= n; len += len) {
rep(i, 0, n - 1) tmp[i] = (suff[i] - len + n) % n;
memset(cnt, 0, sizeof cnt);
rep(i, 0, n - 1) cnt[c[suff[i]]]++;
calc();
rep(i, 0, n - 1) suff[cnt[c[tmp[i]]]++] = tmp[i];
nc[suff[0]] = 0;
rep(i, 1, n - 1) {
pair < int, int > cur = { c[suff[i]], c[(suff[i] + len) % n] };
pair < int, int > last = { c[suff[i - 1]], c[(suff[i - 1] + len) % n] };
if(cur == last) nc[suff[i]] = nc[suff[i - 1]];
else nc[suff[i]] = nc[suff[i - 1]] + 1;
}
rep(i, 0, n - 1) c[i] = nc[i];
}
n--;
rep(i, 0, n - 1) suff[i] = suff[i + 1];
}
void build() {
rep(i, 0, n - 1) pos[suff[i]] = i;
int k = 0;
rep(i, 0, n - 1) {
if(k > 0) k--;
if(pos[i] == n - 1) {
k = 0;
lcp[n - 1] = 0;
}
else {
int j = suff[pos[i] + 1];
while(k <= n && max(i + k, j + k) < n && s[(i + k) % n] == s[(j + k) % n]) k++;
lcp[pos[i]] = k;
}
}
}
bool ok(int l, int r) {
if(l > r) return 1;
if(s[l] != s[r]) return 0;
return ok(l+1, r-1);
}
int sv[MAXN];
ll get(int i, int len1) {
int l = i, kol = 1, r = i+1;
while(l >= 0 && lcp[l] >= len1) l--;
while(r <= n-2 && lcp[r] >= len1) r++;
l++, r--;
kol += r - l + 1;
return kol*1ll*len1;
}
int main() {
#ifdef accepted
freopen(".in", "r", stdin);
freopen(".out", "w", stdout);
#endif
// onlycin;
scanf("%s", s);
n = strlen(s);
SA();
build();
ll res = 0ll;
int mx = 0;
rep(i, 0, n-1) {
int len = n-suff[i];
while(!ok(suff[i], suff[i]+len-1)) len--;
sv[i] = len;
updmax(mx, len);
}
rep(len, 1, mx) {
int cur = 1, cnt = 1;
rep(i, 0, n-1) {
if(lcp[i] >= len) cur++;
else cur = 1;
updmax(cnt, cur);
}
updmax(res, len*1ll*cnt);
}
cout << res << nxtl;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
palindrome.cpp: In function 'void SA()':
palindrome.cpp:45:27: warning: array subscript has type 'char' [-Wchar-subscripts]
rep(i, 0, n - 1) cnt[s[i]]++;
^
palindrome.cpp:48:16: warning: array subscript has type 'char' [-Wchar-subscripts]
suff[cnt[s[i]]++] = i;
^
palindrome.cpp: In function 'int main()':
palindrome.cpp:112:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%s", 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... |