Submission #885035

#TimeUsernameProblemLanguageResultExecution timeMemory
885035patrikpavic2Palindromes (APIO14_palindrome)C++17
100 / 100
109 ms84656 KiB
#include <algorithm> #include <vector> #include <cstdio> #include <cstring> #include <iostream> #define PB push_back using namespace std; typedef long long ll; const int N = 3e5 + 500; const int INF = 0x3f3f3f3f; struct node{ node* CH[30]; node* bk; int len, cnt; } *n0, *n1; bool cmp(node* X, node* Y){ return X -> len > Y -> len; } string s; int n; ll mx; vector < node* > v; void precompute(){ n1 = new node(); n0 = new node(); n1 -> len = -1, n0 -> len = 0; n0 -> bk = n1; n1 -> bk = n1; node* cur = n0; for(int i = 0;i < n;i++){ for(; cur->len + 1 > i || s[i - cur->len - 1] != s[i]; cur = cur -> bk); node *rmb = cur -> bk; if(cur -> CH[s[i] - 'a'] == NULL) cur -> CH[s[i] - 'a'] = new node(), v.PB(cur -> CH[s[i] - 'a']); cur -> CH[s[i] - 'a'] -> len = cur -> len + 2; cur = cur -> CH[s[i] - 'a']; cur -> cnt++; //printf("len = %d\n", cur -> len); for(; rmb -> len + 1 > i || s[i - rmb->len - 1] != s[i]; rmb = rmb -> bk); if(cur -> len == 1) cur -> bk = n0; else{ if(rmb -> CH[s[i] - 'a'] == NULL) rmb -> CH[s[i] - 'a'] = new node(), v.PB(rmb -> CH[s[i] - 'a']); cur -> bk = rmb -> CH[s[i] - 'a']; } //printf("bk = %d\n", cur -> bk -> len); } } int main(){ cin >> s; n = (int)s.size(); precompute(); sort(v.begin(), v.end(), cmp); for(int i = 0;i < v.size();i++){ mx = max(mx, (ll)v[i] -> len * v[i] -> cnt); v[i] -> bk -> cnt += v[i] -> cnt; } cout << mx << endl; }

Compilation message (stderr)

palindrome.cpp: In function 'int main()':
palindrome.cpp:64:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<node*>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |     for(int i = 0;i < v.size();i++){
      |                   ~~^~~~~~~~~~
#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...