제출 #1335202

#제출 시각아이디문제언어결과실행 시간메모리
1335202Faisal_SaqibRima (COCI17_rima)C++20
0 / 140
722 ms327680 KiB
#include <iostream>
#include <map>
#include <bits/stdc++.h>
#include <vector>
using namespace std;
const long long mod=1e9+7;
int ans=0;
const int M=3e6+100;
map<int,int> z[M],o[M];
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		string s;
		cin>>s;
		int l=s.size();
		int ohsh=0,zhsh=0;
		for(int j=l-1;j>=0;j--)
		{
			zhsh=(1ll*zhsh*29+(s[j]-'a'+1))%mod;
			if(j==1)ohsh=zhsh;
		}
		int dp=max({z[l-1][ohsh],z[l][zhsh],o[l][ohsh],o[l+1][zhsh]})+1;
		// cout<<"at "<<i<<' '<<s<<' '<<dp<<endl;
		z[l][zhsh]=max(z[l][zhsh],dp);
		o[l][ohsh]=max(o[l][ohsh],dp);
		ans=max(ans,dp);
	}
	cout<<ans<<endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...