이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
struct debug {
#define contPrint { *this << "["; \
int f = 0; for(auto it : x) { *this << (f?", ":""); *this << it; f = 1;} \
*this << "]"; return *this;}
~debug(){cerr << endl;}
template<class c> debug& operator<<(c x) {cerr << x; return *this;}
template<class c, class d>
debug& operator<<(pair<c, d> x) {*this << "(" << x.first << ", " << x.second << ")";
return *this;}
template<class c> debug& operator<<(vector<c> x) contPrint;
#undef contPrint
};
#define dbg(x) "[" << #x << ": " << x << "] "
#define Wa() cerr << "[LINE: " << __LINE__ << "] -> "; debug() <<
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL);
const int N = 3e5 + 5;
int tree[N][26], idx;
int len[N], lnk[N], t;
char ch[N];
void init()
{
len[1] = -1, lnk[1] = 1;
len[2] = 0, lnk[2] = 1;
idx = t = 2;
}
int cnt[N];
i64 ans = 0;
void extend(int p)
{
while(ch[p - len[t] - 1] != ch[p]) t = lnk[t];
int x = lnk[t], c = ch[p] - 'a';
while(ch[p - len[x] - 1] != ch[p]) x = lnk[x];
if(!tree[t][c]) {
tree[t][c] = ++idx;
len[idx] = len[t] + 2;
lnk[idx] = len[idx] == 1 ? 2 : tree[x][c];
}
t = tree[t][c];
cnt[t]++;
}
int main()
{
init();
scanf("%s", ch + 1);
for(int i = 1; ch[i]; i++) {
extend(i);
}
for(int i = idx; i > 2; i--) {
cnt[lnk[i]] += cnt[i];
}
for(int i = 3; i <= idx; i++) {
ans = max(ans, 1LL * len[i] * cnt[i]);
}
printf("%lld\n", ans);
}
컴파일 시 표준 에러 (stderr) 메시지
palindrome.cpp: In function 'int main()':
palindrome.cpp:57:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
57 | scanf("%s", ch + 1);
| ~~~~~^~~~~~~~~~~~~~
# | 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... |