Submission #564088

#TimeUsernameProblemLanguageResultExecution timeMemory
564088perchutsSavez (COCI15_savez)C++17
0 / 120
145 ms65536 KiB
#include <bits/stdc++.h> #define all(x) x.begin(), x.end() #define sz(x) (int) x.size() #define endl '\n' #define pb push_back #define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); using namespace std; using ll = long long; using ull = unsigned long long; using ii = pair<int,int>; using iii = tuple<int,int,int>; const int inf = 2e9+1; const ll mod = 1e9+7; const ll base = 101; template<typename X, typename Y> bool ckmin(X& x, const Y& y) { return (y < x) ? (x=y,1):0; } template<typename X, typename Y> bool ckmax(X& x, const Y& y) { return (x < y) ? (x=y,1):0; } vector<int>sorted,qnt; bool cmp(int a,int b){ return qnt[a]>qnt[b]; } vector<vector<ll>>hsh, revHsh; vector<string>v; ll mul[2000001]; void computeHash(int idx){ int n = qnt[idx]; hsh[idx].pb(ll(v[idx][0]-'A')); for(int i=1;i<n;++i){ ll add = hsh[idx].back()*base+ll(v[idx][i]-'A'); hsh[idx].pb(add); hsh[idx].back() %= mod; } revHsh[idx].pb(ll(v[idx][n-1]-'A')); for(int i=n-2;i>=0;--i){ ll add = revHsh[idx].back()+mul[n-1-i]*ll(v[idx][i]-'A'); revHsh[idx].pb(add); revHsh[idx].back() %= mod; } } unordered_map<int,int>dp; int main(){_ int n;cin>>n; v.resize(n), sorted.resize(n), qnt.resize(n); for(int i=0;i<n;++i){ cin>>v[i]; qnt[i] = sz(v[i]); } mul[0] = 1ll; for(int i=1;i<=2e6;++i)mul[i] = (mul[i-1]*base)%mod; iota(all(sorted),0); sort(all(sorted), cmp); hsh.resize(n), revHsh.resize(n); int best = 0; for(int i=0;i<n;++i){ int idx = sorted[i]; computeHash(idx); int m = qnt[idx]; int me = int(hsh[idx][m-1]); int res = dp[me]+1; for(int j=0;j<m;++j)if(hsh[idx][j]==revHsh[idx][j])ckmax(dp[int(hsh[idx][j])], res); ckmax(best, res); } cout<<best<<endl; }
#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...
#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...