# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
994137 | vjudge1 | Rima (COCI17_rima) | C++17 | 960 ms | 77804 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5;
#define int long long
bool not_pr[N];
signed main()
{
ios::sync_with_stdio(0);
cin.tie(NULL),cout.tie(NULL);
vector<long long> hashes,modes={1LL<<50,1LL<<55,1LL<<40,1LL<<36,1LL<<45};
for (int i=2;i<N;i++)
for (int j=i+i;j<N;j+=i)
not_pr[j]=true;
for (int i=200;i<N;i++)
if (!not_pr[i])
{
hashes.push_back(i);
i+=100;
}
srand(time(NULL));
long long h=hashes[rand()%2725],h1=hashes[rand()%2725];
int mod = modes[rand()%5],mod1=modes[rand()%5];
int h2 = hashes[rand()%2725],mod2=modes[rand()%5];
int n;
cin>>n;
map<int,vector<string>> mp;
unordered_set<int> se;
se.reserve(n+369);
for (int i=0;i<n;i++)
{
string s;
cin>>s;
reverse(s.begin(),s.end());
mp[s.size()].push_back(s);
int m=s.size(),hs=0,hs1=0;
for (int j=0;j<m;j++)
hs=(hs*h+s[j])%mod;
for (int j=0;j<m;j++)
hs1=(hs1*h1+s[j])%mod1;
se.insert((hs+hs1*h2)%mod2);
}
vector<string> v;
for (auto i:mp)
for (auto j:i.second)
v.push_back(j);
reverse(v.begin(),v.end());
unordered_map<int,int> ans;
ans.reserve(n+369);
while (!v.empty())
{
string s=v.back();
v.pop_back();
int m=s.size();
int hs=0,mx=0,hs1=0;
for (int i=0;i<m-1;i++)
hs=(hs*h+s[i])%mod;
for (int i=0;i<m-1;i++)
hs1=(hs1*h1+s[i])%mod1;
if (ans.find((hs+hs1*h2)%mod2)!=ans.end())
mx=ans[(hs+hs1*h2)%mod2];
for (int c='a';c<='z';c++)
{
int p=((hs*h+c)%mod+(hs1*h1+c)%mod1*h2)%mod2;
if (se.find(p)!=se.end())
mx++;
}
int c=s[m-1];
int p=((hs*h+c)%mod+(hs1*h1+c)%mod1*h2)%mod2;
ans[p]=mx;
}
int res=0;
for (auto i:ans)
res=max(res,i.second);
cout<<res<<endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |