Submission #1119741

#TimeUsernameProblemLanguageResultExecution timeMemory
1119741raczekPalindromes (APIO14_palindrome)C++17
0 / 100
1063 ms131072 KiB
#include<bits/stdc++.h> using namespace std; #ifdef DEBUG auto& operator <<(auto& o, pair<auto, auto> p) {return o<<"{"<<p.first<<", "<<p.second<<"}";} auto operator <<(auto& o, auto x)->decltype(x.end(), o) {o<<"{"; for(auto v : x) o<<v<<", "; return o<<"}";} #define debug(X) cerr<<"["#X"]: "<<X<<endl; #else #define debug(X) {} #endif #define int long long struct palTrie { struct node { node* sons[30]; vector<node*> edg; node* sufLink = nullptr; int val = 0; int sz = -1; node(node* suf, int s){ sufLink = suf, sz = s; for(int i=0;i<30;i++) sons[i] = nullptr; } node(){ for(int i=0;i<30;i++) sons[i] = nullptr; } }; string s; node Oroot; node* add(char let, int pos, node* prev) { debug(let); debug(pos); node* nw = nullptr; while(prev != nullptr) { if(pos-1-prev->sz >= 0 && s[pos-1-prev->sz]-'a' == let) { if(nw == nullptr) { bool e = 0; if(prev->sons[let] == nullptr) { prev->sons[let] = new node(&Oroot, prev->sz + 2); e = true; } nw = prev->sons[let]; nw->val++; if(!e) break; } else { nw->sufLink = prev->sons[let]; break; } } prev = prev->sufLink; } nw->sufLink->edg.push_back(nw); return nw; } int res = 0; int dfs(node* a) { int sum = a->val; for(auto v : a->edg) sum += dfs(v); debug(a->sz); debug(sum); if(a->sz != -1) res = max(res, sum * (a->sz/2)); return sum; } palTrie(string _s) { s = _s; int k = 0; node* p = &Oroot; for(auto v : s) p = add(v - 'a', k++, p); dfs(&Oroot); } }; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); string s; cin>>s; char g = 'z' + 1; string t = ""; t += g; for(auto v : s) {t += v; t += g;} s = t; debug(s); palTrie A(s); debug(A.res); cout<<A.res; }

Compilation message (stderr)

palindrome.cpp: In member function 'palTrie::node* palTrie::add(char, long long int, palTrie::node*)':
palindrome.cpp:42:20: warning: array subscript has type 'char' [-Wchar-subscripts]
   42 |      if(prev->sons[let] == nullptr)
      |                    ^~~
palindrome.cpp:44:17: warning: array subscript has type 'char' [-Wchar-subscripts]
   44 |      prev->sons[let] = new node(&Oroot, prev->sz + 2);
      |                 ^~~
palindrome.cpp:47:22: warning: array subscript has type 'char' [-Wchar-subscripts]
   47 |      nw = prev->sons[let];
      |                      ^~~
palindrome.cpp:53:31: warning: array subscript has type 'char' [-Wchar-subscripts]
   53 |      nw->sufLink = prev->sons[let];
      |                               ^~~
#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...