Submission #941993

#TimeUsernameProblemLanguageResultExecution timeMemory
941993JoseSotoPalindromes (APIO14_palindrome)C++14
100 / 100
35 ms63172 KiB
#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; } ll dp(){ ll ans = 0; for(int i=n-1; i>=0; i--){ et[ et[i].link ].cnt += et[i].cnt; ans = max(ans, 1LL*et[i].l*et[i].cnt); } return ans; } }; int main() { ios_base::sync_with_stdio(0); cin.tie(0); string s; cin >> s; eertree et; for(auto ch: s) et.add(ch); cout << et.dp() << "\n"; return 0; }

Compilation message (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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...