# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
165720 | Sensei | Lozinke (COCI17_lozinke) | C++17 | 1084 ms | 19128 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 long long P = 53;
const long long MOD = 1e9 + 7;
const int MAXN = 2e4;
long long add (long long x, long long y) {
return ((x % MOD) + (y % MOD)) % MOD;
}
long long mul (long long x, long long y) {
return ((x % MOD) * (y % MOD)) % MOD;
}
unordered_map<long long, set<int> > m;
string st[MAXN + 7];
int main () {
int N;
cin >> N;
for (int i = 1; i <= N; i++) {
cin >> st[i];
}
for (int i = 1; i <= N; i++) {
long long hash = 0;
for (int j = 0; j < st[i].size(); j++) {
hash = mul(hash, P);
hash = add(hash, st[i][j] - 'a' + 1);
}
m[hash].insert(i);
}
long long ans = 0;
for (int i = 1; i <= N; i++) {
set<int> s;
for (int ss = 0; ss < st[i].size(); ss++) {
long long hash = 0;
for (int j = ss; j < st[i].size(); j++) {
if (ss == 0 && j + 1 == st[i].size()) {
break;
}
hash = mul(hash, P);
hash = add(hash, st[i][j] - 'a' + 1);
for (int id : m[hash]) {
if (id != i) {
s.insert(id);
}
}
}
}
ans += s.size();
}
long long ans2 = 0;
for (int i = 1; i <= N; i++) {
long long hash = 0;
for (int j = 0; j < st[i].size(); j++) {
hash = mul(hash, P);
hash = add(hash, st[i][j] - 'a' + 1);
}
ans2 += m[hash].size() - 1;
}
ans += ans2;
cout << ans << "\n";
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |