Submission #134908

#TimeUsernameProblemLanguageResultExecution timeMemory
134908CaroLindaPalindromes (APIO14_palindrome)C++14
8 / 100
1060 ms131072 KiB
#include <bits/stdc++.h> #define lp(i,a,b) for(int i=a;i<b;i++) #define pii pair<int,int> #define ll long long #define ff first #define ss second #define pb push_back #define mk make_pair const int inf = 0x3f3f3f3f ; const int MAXN = 1010 ; const int ALF = 30 ; const int SZTRIE = MAXN*MAXN ; using namespace std ; //Se der errado, checar o limite da trie struct Trie { int trie[SZTRIE][ALF] , nodes ; ll qtd[SZTRIE] ; Trie() { memset(trie,0,sizeof trie ) ; memset(qtd,0,sizeof qtd) ; nodes = 0 ; } void add(char str[] , int l , int r) { int cur = 0 ; for(int i = l ; i < r ; i++ ) { int c = str[i] - 'a' ; if( trie[cur][c] == 0 ) trie[cur][c] = ++nodes ; cur = trie[cur][c] ; } qtd[cur] ++ ; } ll findQtd(char str[] , int l , int r) { int cur = 0 ; for(int i = l ; i < r ; i++ ) { int c = str[i]-'a' ; if(trie[cur][c] == 0) return 0 ; cur = trie[cur][c] ; } return qtd[cur] ; } } ; int n ; char str[MAXN] ; bool s[MAXN][MAXN] ; Trie myTrie ; void findPalindrome() { lp(i,0,n) s[i][i] = true ; lp(i,0,n-1) if( str[i] == str[i+1] ) s[i][i+1] = true ; lp(i,2,n) for(int j = 0 ; j + i < n ; j++ ) s[j][j+i] = ( s[j+1][j+i-1] && (str[j]==str[j+i]) ) ; } int main() { scanf(" %s", str ) ; n = strlen(str) ; findPalindrome() ; lp(i,0,n) lp(j,i, n) myTrie.add(str,i,j+1) ; ll ans = 0 ; lp(i,0,n) lp(j,i,n) if(s[i][j]) ans = max(ans, myTrie.findQtd(str, i , j+1)*(j-i+1) ) ; printf("%lld\n" , ans ); }

Compilation message (stderr)

palindrome.cpp: In function 'int main()':
palindrome.cpp:85:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf(" %s", str ) ;
  ~~~~~^~~~~~~~~~~~~
#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...