제출 #604025

#제출 시각아이디문제언어결과실행 시간메모리
604025inksamuraiSavez (COCI15_savez)C++17
0 / 120
110 ms51648 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; tmp.pb(rs); } std::map<string,int> mp; int cnt=0; for(auto &s:tmp){ if(mp.find(s)==mp.end()){ mp[s]=cnt++; } } const int m=cnt; // 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(mp.find(now)!=mp.end()){ int ni=mp[now]; // 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...