# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1078057 | khactrung1912 | Lozinke (COCI17_lozinke) | C++14 | 153 ms | 3664 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 nx=2e4+5, mod=19122007;
#define ll long long
ll n, c[nx][12], sz[nx], res, p[nx], vl[nx];
string s;
map<ll, ll> mp;
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
p[0]=1;
for (int i=1; i<=10; i++) p[i]=(p[i-1]*30)%mod;
cin>>n;
for (int i=1; i<=n; i++)
{
cin>>s;
sz[i]=s.size();
for (int j=1; j<=sz[i]; j++) c[i][j]=s[j-1]-'a'+1;
}
for (int i=1; i<=n; i++)
{
set<ll> s;
for (int j=1; j<=sz[i]; j++)
{
ll tmp=0;
for (int k=j; k<=sz[i]; k++)
{
tmp=(tmp+c[i][k]*p[k-j])%mod;
s.insert(tmp);
if (j==1&&k==sz[i]) vl[i]=tmp;
}
}
for (auto x:s) if (mp.find(x)!=mp.end()) res+=mp[x];
mp[vl[i]]++;
}
mp.clear();
for (int i=n; i>=1; i--)
{
set<ll> s;
for (int j=1; j<=sz[i]; j++)
{
ll tmp=0;
for (int k=j; k<=sz[i]; k++)
{
tmp=(tmp+c[i][k]*p[k-j])%mod;
s.insert(tmp);
}
}
for (auto x:s) if (mp.find(x)!=mp.end()) res+=mp[x];
mp[vl[i]]++;
}
cout<<res;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |