# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1011937 | 0npata | Lozinke (COCI17_lozinke) | C++17 | 185 ms | 13316 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;
#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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |