Submission #257278

# Submission time Handle Problem Language Result Execution time Memory
257278 2020-08-04T03:53:16 Z kshitij_sodani Rima (COCI17_rima) C++14
56 / 140
408 ms 147232 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define mp make_pair
#define pb push_back
#define a first 
#define b second
int co=0;
int n;
int pre[3000001][26];
vector<int> kk[3000001];
int val[3000001];
int dp[3000001];
void insert(string s){
	int cur=0;
	for(int i=s.size()-1;i>=0;i--){
		if(pre[cur][s[i]-'a']==0){
			co+=1;
			pre[cur][s[i]-'a']=co;
			kk[cur].pb(co);
		}
		cur=pre[cur][s[i]-'a'];
	}
	val[cur]+=1;
	if(val[cur]>1){
		while(true){
			continue;
		}
	}
}
int ans=0;
void dfs(int no){
	int su=0;
	for(auto j:kk[no]){
		dfs(j);
		su+=dp[j];
	}
	ans=max(ans,su);
	if(val[no]==1){
		dp[no]=su+1;
		ans=max(ans,su+1);
	}
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n;
	for(int i=0;i<n;i++){
		string s;
		cin>>s;
		//	int x=s.size();
		insert(s);
	}
	dfs(0);
	cout<<ans<<endl;



	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 42 ms 70776 KB Output is correct
2 Correct 42 ms 70912 KB Output is correct
3 Correct 44 ms 70776 KB Output is correct
4 Incorrect 408 ms 147232 KB Output isn't correct
5 Correct 60 ms 71288 KB Output is correct
6 Incorrect 102 ms 125232 KB Output isn't correct
7 Incorrect 104 ms 125128 KB Output isn't correct
8 Incorrect 92 ms 125064 KB Output isn't correct
9 Incorrect 125 ms 126980 KB Output isn't correct
10 Incorrect 98 ms 125104 KB Output isn't correct