Submission #116847

# Submission time Handle Problem Language Result Execution time Memory
116847 2019-06-14T02:36:53 Z ntrung03 Lozinke (COCI17_lozinke) C++17
100 / 100
410 ms 15188 KB
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 17967929219605081
#define base 31
string s[20002];
int h[20002][12];
int p[12];
signed main() {
	int n;
	cin>>n;
	p[0] = 1;
	for(int i=1;i<12;i++)p[i] = (p[i-1]*base)%mod;
	int res = 0;
	for(int i=0;i<n;i++) cin>>s[i];
	map<pair<int,int>,int> hashes;
	for(int i=0;i<n;i++)
	{
		int l = s[i].size();
		for(int j=0;j<l;j++)
		{
			h[i][j] = (j>0?h[i][j-1]:0);
			h[i][j] = ((h[i][j]*base)%mod+s[i][j]-'a'+1)%mod;
		}
		hashes[{h[i][l-1],l}]+=1;
	}
	for(int k =0;k<n;k++)
	{
		int l = s[k].size();
		set<pair<int,int>> ck;
		for(int i=0;i<l;i++)
		for(int j=i;j<l;j++){
			long long ph = h[k][j]-(i>0?h[k][i-1]*p[j-i+1]:0)%mod;
			pair<int,int> hh = {ph,j-i+1};
			if(ck.count(hh)) continue;
			res+=hashes[hh];
			ck.insert(hh);
		}
	}
	printf("%lld",res-n);
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1024 KB Output is correct
2 Correct 3 ms 896 KB Output is correct
3 Correct 3 ms 1024 KB Output is correct
4 Correct 4 ms 1024 KB Output is correct
5 Correct 8 ms 1408 KB Output is correct
6 Correct 11 ms 1408 KB Output is correct
7 Correct 15 ms 2048 KB Output is correct
8 Correct 25 ms 2680 KB Output is correct
9 Correct 51 ms 3320 KB Output is correct
10 Correct 157 ms 7372 KB Output is correct
11 Correct 98 ms 5220 KB Output is correct
12 Correct 397 ms 14968 KB Output is correct
13 Correct 142 ms 4304 KB Output is correct
14 Correct 269 ms 14160 KB Output is correct
15 Correct 410 ms 15188 KB Output is correct
16 Correct 116 ms 2944 KB Output is correct
17 Correct 28 ms 2816 KB Output is correct
18 Correct 23 ms 2816 KB Output is correct
19 Correct 230 ms 8956 KB Output is correct
20 Correct 61 ms 2944 KB Output is correct