Submission #1011937

# Submission time Handle Problem Language Result Execution time Memory
1011937 2024-07-01T11:19:00 Z 0npata Lozinke (COCI17_lozinke) C++17
100 / 100
185 ms 13316 KB
#include<bits/stdc++.h>
using namespace std;

#define int long long
#define vec vector

const int MX = 1e9+7;

mt19937 rng(54);

int rng_next(int mx) {
	return uniform_int_distribution<int32_t>(0, mx)(rng);
}

int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int n;
	cin >> n;
	vec<string> a(n);

	for(int i = 0; i<n; i++) cin >> a[i];

	vec<int> pos_hash(10);
	vec<int> let_hash(26);

	for(int i = 0; i<10; i++) {
		pos_hash[i] = rng_next(MX);
	}
	for(int i = 0; i<26; i++) {
		let_hash[i] = rng_next(MX);
	}

	map<int, int> cnt;

	for(int i = 0; i<a.size(); i++) {
		set<int> subs;
		for(int j = 0; j < a[i].size(); j++) {
			int hash = 0;
			for(int k = j; k<a[i].size(); k++) {
				int pos = k-j;
				hash += pos_hash[pos] * let_hash[a[i][k]-'a'];
				subs.insert(hash);
			}
		}

		for(int subh : subs) {
			cnt[subh] += 1;
		}
	}

	int ans = 0;
	for(int i = 0; i<n; i++) {
		int hash = 0;
		for(int j = 0; j<a[i].size(); j++) {
			hash += pos_hash[j] * let_hash[a[i][j]-'a'];
		}
		ans += cnt[hash]-1;
	}

	cout << ans << '\n';

}

Compilation message

lozinke.cpp: In function 'int32_t main()':
lozinke.cpp:37:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |  for(int i = 0; i<a.size(); i++) {
      |                 ~^~~~~~~~~
lozinke.cpp:39:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |   for(int j = 0; j < a[i].size(); j++) {
      |                  ~~^~~~~~~~~~~~~
lozinke.cpp:41:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |    for(int k = j; k<a[i].size(); k++) {
      |                   ~^~~~~~~~~~~~
lozinke.cpp:56:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |   for(int j = 0; j<a[i].size(); j++) {
      |                  ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 3 ms 756 KB Output is correct
6 Correct 4 ms 604 KB Output is correct
7 Correct 7 ms 1372 KB Output is correct
8 Correct 13 ms 1884 KB Output is correct
9 Correct 26 ms 2140 KB Output is correct
10 Correct 81 ms 6184 KB Output is correct
11 Correct 44 ms 3636 KB Output is correct
12 Correct 169 ms 13316 KB Output is correct
13 Correct 75 ms 2388 KB Output is correct
14 Correct 122 ms 12112 KB Output is correct
15 Correct 185 ms 13140 KB Output is correct
16 Correct 68 ms 1200 KB Output is correct
17 Correct 12 ms 860 KB Output is correct
18 Correct 9 ms 860 KB Output is correct
19 Correct 106 ms 6912 KB Output is correct
20 Correct 35 ms 1116 KB Output is correct