Submission #173649

#TimeUsernameProblemLanguageResultExecution timeMemory
173649NucleistPalindromes (APIO14_palindrome)C++14
8 / 100
1090 ms8768 KiB
#include <bits/stdc++.h> using namespace std; #pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") #define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0) #define debug(x) cerr << " - " << #x << ": " << x << endl; #define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl; #define all(x) (x).begin(),(x).end() #define sz(x) (ll)x.size() #define ll long long #define INF 1000000000 #define MOD 1000000007 #define pb push_back #define ve vector<ll> #define dos pair<ll,ll> #define vedos vector<dos> #define rand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) struct greateri { template<class T> bool operator()(T const &a, T const &b) const { return a > b; } }; vector<ll> rabin_karp(string const& s, string const& t) { const ll p = 31; const ll m = 1e9 + 9; ll S = s.size(), T = t.size(); vector<long long> p_pow(max(S, T)); p_pow[0] = 1; for (ll i = 1; i < (ll)p_pow.size(); i++) p_pow[i] = (p_pow[i-1] * p) % m; vector<long long> h(T + 1, 0); for (ll i = 0; i < T; i++) h[i+1] = (h[i] + (t[i] - 'a' + 1) * p_pow[i]) % m; long long h_s = 0; for (ll i = 0; i < S; i++) h_s = (h_s + (s[i] - 'a' + 1) * p_pow[i]) % m; vector<ll> occurences; for (ll i = 0; i + S - 1 < T; i++) { long long cur_h = (h[i+S] + m - h[i]) % m; if (cur_h == h_s * p_pow[i] % m) occurences.push_back(i); } return occurences; } int main() { //flash; string a; cin>>a; ll ans=0; for (ll i = 0; i < a.size(); ++i) { for (ll j = i; j < a.size(); ++j) { string dol; ll ka=0; for (ll k = i; k <= j; ++k) { dol+=a[k]; } string hey=dol; reverse(hey.begin(),hey.end()); if(hey==dol) { ve hi = rabin_karp(dol,a); ka=hi.size(); ans=max(ans,ka*(j-i+1)); } } } cout<<ans; return 0; } //code the AC sol ! // BS/queue/map

Compilation message (stderr)

palindrome.cpp:4:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization ("O3")
 
palindrome.cpp:5:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization ("unroll-loops")
 
palindrome.cpp: In function 'int main()':
palindrome.cpp:55:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (ll i = 0; i < a.size(); ++i)
                  ~~^~~~~~~~~~
palindrome.cpp:57:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (ll j = i; j < a.size(); ++j)
                    ~~^~~~~~~~~~
#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...