Submission #994072

# Submission time Handle Problem Language Result Execution time Memory
994072 2024-06-07T05:43:12 Z vjudge1 Rima (COCI17_rima) C++17
0 / 140
1000 ms 81264 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long

const int h = 7369, mod = 1LL<<36;
const int M = 3e6;

int pw[M];

signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(NULL),cout.tie(NULL);
	
	pw[0]=1;
	for (int i=1;i<M;i++)
		pw[i]=pw[i-1]*h%mod;
	int n;
	cin>>n;
	map<int,vector<string>> mp;
	for (int i=0;i<n;i++)
	{
		string s;
		cin>>s;
		mp[s.size()].push_back(s);
	}
	vector<string> v;
	for (auto i:mp)
		for (auto j:i.second)
			v.push_back(j);
	reverse(v.begin(),v.end());
	map<int,int> ans;
	while (!v.empty())
	{
		string s=v.back();
		v.pop_back();
		int hs=0,m=s.size();
		for (int i=1;i<m;i++)
			hs=hs*h+s[i],hs%=mod;
		int mx;
		if (ans.find(hs)!=ans.end())
			mx=ans[hs]+1;
		else
			mx=1;
		vector<int> wht;
		int p;
		for (int c='a';c<='z';c++)
		{
			p=hs;
			p+=pw[m-1]*c%mod;
			if (ans.find(p)!=ans.end())
				mx=max(mx,ans[p]+1),wht.push_back(p);
			else if(c==s[0])
				wht.push_back(p);
				
		}
		for (int i:wht)
			ans[i]=mx;
	}
	int res=0;
	for (auto i:ans)
		res=max(res,i.second);
	cout<<res<<endl;
	
	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 23900 KB Output isn't correct
2 Incorrect 20 ms 23900 KB Output isn't correct
3 Incorrect 22 ms 23716 KB Output isn't correct
4 Execution timed out 1076 ms 81264 KB Time limit exceeded
5 Incorrect 37 ms 33012 KB Output isn't correct
6 Incorrect 23 ms 26564 KB Output isn't correct
7 Incorrect 22 ms 26196 KB Output isn't correct
8 Incorrect 22 ms 25748 KB Output isn't correct
9 Incorrect 78 ms 34700 KB Output isn't correct
10 Incorrect 23 ms 25912 KB Output isn't correct