Submission #604023

#TimeUsernameProblemLanguageResultExecution timeMemory
604023inksamuraiSavez (COCI15_savez)C++17
96 / 120
487 ms63056 KiB
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<n;i++) #define rng(i,c,n) for(int i=(c);i<n;i++) #define per(i,n) for(int i=n-1;i>=0;i--) #define fi first #define se second #define pb push_back #define sz(a) (int)a.size() #define vec(...) vector<__VA_ARGS__> #define _3aFGabX ios::sync_with_stdio(0),cin.tie(0) typedef long long ll; using pii=pair<int,int>; using vi=vector<int>; void print(){cout<<'\n';} template<class h,class...t> void print(const h&v,const t&...u){cout<<v<<' ',print(u...);} // e // kactl : Z function vi Z(string S) { vi z(sz(S)); int l = -1, r = -1; rng(i,1,sz(S)) { z[i] = i >= r ? 0 : min(r - i, z[i - l]); while (i + z[i] < sz(S) && S[i + z[i]] == S[z[i]]) z[i]++; if (i + z[i] > r) l = i, r = i + z[i]; } return z; } signed main(){ _3aFGabX; int n; cin>>n; vec(string) a,tmp; rep(i,n){ string s; cin>>s; a.pb(s); string rs=s; reverse(rs.begin(), rs.end()); tmp.pb(rs); } sort(tmp.begin(), tmp.end()); tmp.erase(unique(tmp.begin(), tmp.end()),tmp.end()); const int m=sz(tmp); // sort(a.begin(), a.end(),[&](const string&l,const string&r){ // return sz(l)<sz(r); // }); vi dp(m,0); rep(i,n){ vi z=Z(a[i]); // rep(j,sz(a[i])){ // cout<<z[j]<<" "; // } // print("...."); int id=(int)(lower_bound(tmp.begin(), tmp.end(),a[i])-tmp.begin()); string now=""; int res=dp[id]; per(j,sz(a[i])){ now+=a[i][j]; if(!j or z[j]==sz(a[i])-j){ if(lower_bound(tmp.begin(), tmp.end(),now)!=tmp.end()){ int ni=(int)(lower_bound(tmp.begin(), tmp.end(),now)-tmp.begin()); // if(i==2) print(ni); res=max(res,dp[ni]+1); } } } dp[id]=res; // print(id,dp[id],a[i]); } print(*max_element(dp.begin(), dp.end())); }
#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...