# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
994105 |
2024-06-07T06:25:48 Z |
vjudge1 |
Rima (COCI17_rima) |
C++17 |
|
454 ms |
85420 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
const long long mod = 1LL<<42;
const int M = 3e6, N = M/20;
long long pw[M];
bool not_pr[N];
signed main()
{
ios::sync_with_stdio(0);
cin.tie(NULL),cout.tie(NULL);
vector<long long> hashes;
for (int i=2;i<N;i++)
for (int j=i+i;j<N;j+=i)
not_pr[j]=true;
for (int i=100;i<N;i++)
if (!not_pr[i])
{
hashes.push_back(i);
i+=100;
}
srand(time(NULL));
srand(rand());
long long h=hashes[rand()%1372];
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);
}
unordered_map<long long,int> ans;
ans.reserve(500369);
for (auto what:mp)
{
unordered_map<long long,int> temp,cnt;
temp.reserve(what.second.size()+369);
cnt.reserve(what.second.size()+369);
for (auto s:what.second)
{
long long hs=0;
int 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;
for (int c='a';c<='z';c++)
{
if (ans.find((hs+pw[m-1]*c%mod)%mod)!=ans.end())
mx=max(mx,ans[(hs+pw[m-1]*c%mod)%mod]+1);
}
temp[hs]=mx;
cnt[hs]++;
}
for (auto s:what.second)
{
long long hs=0;
int m=s.size();
for (int i=1;i<m;i++)
hs=hs*h+s[i],hs%=mod;
char c=s[0];
ans[(hs+pw[m-1]*c%mod)%mod]=temp[hs]+cnt[hs]-1;
}
}
int res=0;
for (auto i:ans)
res=max(res,i.second);
cout<<res<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
27988 KB |
Output is correct |
2 |
Correct |
20 ms |
27996 KB |
Output is correct |
3 |
Correct |
18 ms |
28004 KB |
Output is correct |
4 |
Incorrect |
454 ms |
85420 KB |
Output isn't correct |
5 |
Correct |
45 ms |
31312 KB |
Output is correct |
6 |
Incorrect |
24 ms |
29632 KB |
Output isn't correct |
7 |
Incorrect |
24 ms |
29264 KB |
Output isn't correct |
8 |
Incorrect |
22 ms |
29216 KB |
Output isn't correct |
9 |
Incorrect |
48 ms |
33144 KB |
Output isn't correct |
10 |
Incorrect |
24 ms |
29232 KB |
Output isn't correct |