| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 498673 | BrehamPie | 회문 (APIO14_palindrome) | C++14 | 37 ms | 38968 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
using ll = long long;
// cnt - number of palindromic suffixes of the node.
// make string 1 indexed.
struct PalindromicTree {
struct node {
int nxt[26], len, st, en, link, cnt, oc;
};
string s;
vector<node>t;
int sz, last;
PalindromicTree() {}
PalindromicTree( string _s ) {
s = _s;
int n = s.size();
t.resize( n + 5, node() );
sz = 2;
last = 2;
t[1].len = -1, t[1].link = 1;
t[2].len = 0, t[2].link = 1;
}
// returns 1 if new palindrome is found
int extend( int pos ) {
while (s[pos - t[last].len - 1] != s[pos]) last = t[last].link;
int ch = s[pos] - 'a', x = t[last].link;
while (s[pos - t[x].len - 1] != s[pos]) x = t[x].link;
if (t[last].nxt[ch]) {
last = t[last].nxt[ch];
t[last].oc++;
return 0;
}
sz++;
t[sz].oc = 1;
t[sz].len = t[last].len + 2;
t[last].nxt[ch] = sz;
last = sz;
t[sz].en = pos;
t[sz].st = pos - t[sz].len + 1;
if (t[sz].len == 1) {
t[sz].link = 2, t[sz].cnt = 1;
} else {
t[sz].cnt = 1 + t[x].cnt, t[sz].link = t[x].nxt[ch];
}
return 1;
}
void calc_occ() {
for (int i = sz; i >= 3; i--) t[t[i].link].oc += t[i].oc;
}
ll ans(){
ll ret = 0;
for(int i=3;i<=sz;i++){
ret = max(ret,t[i].oc*t[i].len*1ll);
}
return ret;
}
};
int main() {
string str;
cin >> str;
str = '#' + str;
PalindromicTree pt( str );
for (int i = 1; i < str.size(); i++) {
pt.extend( i );
}
cout<<pt.sz-2<<endl;
pt.calc_occ();
cout<<pt.ans()<<endl;
return 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... | ||||
