이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(v) v.begin(), v.end()
#define sz(x) ((int) (x).size())
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vp = vector<pii>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using vb = vector<bool>;
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p){return os << '(' << p.fi << ", " << p.se << ')';}
template<typename C, typename T = typename enable_if<!is_same<C, string>::value, typename C::value_type>::type>
ostream& operator<<(ostream &os, const C &v){string sep; for(const T &x : v) os << sep << x, sep = " "; return os;}
#define deb(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<typename ...Args>
void logger(string vars, Args&&... values){
cout << "[Debug]\n\t" << vars << " = ";
string d = "[";
(..., (cout << d << values, d = "] ["));
cout << "]\n";
}
constexpr short alpha = 26;
constexpr char offset = 'a';
struct state{
int l, link, cnt;
array<int,alpha> go;
state(){
l = cnt = 0;
go.fill(0);
}
};
struct eertree{
int n = 2;
int last = 1;
vector<state> et;
string s;
eertree(){
et.resize(2);
et[0].link = et[1].link = 1;
et[1].l = -1;
}
int palSuff(int x){
while(s[sz(s) - 2 - et[x].l] != s.back()) x = et[x].link;
return x;
}
int add(char ch){
s.pb(ch);
last = palSuff(last);
bool new_pal = !et[last].go[ch-offset];
if(new_pal){
et.pb(state());
et[last].go[ch-offset] = n++;
et.back().link = et[palSuff(et[last].link)].go[ch-offset];
et.back().l = et[last].l + 2;
if(et.back().l == 1) et.back().link = 0;
}
last = et[last].go[ch-offset];
// Do something with last, maybe if new_pal
et[last].cnt++;
if(et[last].l == sz(s)) last = et[last].link;
return new_pal;
}
void computeFrequency(){
for(int i=n-1; i>1; i--)
et[ et[i].link ].cnt += et[i].cnt;
}
};
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
string s;
cin >> s;
eertree et;
for(auto ch: s) et.add(ch);
et.computeFrequency();
ll ans = 0;
for(int i=2; i<et.n; i++) ans = max(ans, 1LL*et.et[i].l*et.et[i].cnt);
cout << ans << "\n";
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
palindrome.cpp: In function 'void logger(std::string, Args&& ...)':
palindrome.cpp:27:42: warning: fold-expressions only available with '-std=c++17' or '-std=gnu++17'
27 | (..., (cout << d << values, d = "] ["));
| ^
# | 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... |