# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
34856 | szawinis | Lozinke (COCI17_lozinke) | C++14 | 1000 ms | 15656 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;
using ll = long long;
const int N = 2e4+1;
const ll MOD = 1e9+7;
int n, ans;
string s[N];
pair<ll, ll> h[N];
map<pair<ll, ll>, int> mp;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for(int i = 0; i < n; i++) {
cin >> s[i];
h[i].first = h[i].second = s[i][0] - 'a' + 1;
for(int j = 1; j < s[i].length(); j++) {
h[i].first = (h[i].first * 31 + s[i][j] - 'a' + 1) % MOD;
h[i].second = (h[i].second * 37 + s[i][j] - 'a' + 1) % MOD;
}
}
for(int i = 0; i < n; i++) {
set<pair<ll, ll> > ls;
for(int x = 0; x < s[i].length(); x++) {
pair<ll, ll> currh = {s[i][x]-'a' + 1, s[i][x]-'a' + 1};
ls.insert(currh);
for(int y = x+1; y < s[i].length(); y++) {
currh.first = (currh.first * 31 + s[i][y] - 'a' + 1) % MOD;
currh.second = (currh.second * 37 + s[i][y] - 'a' + 1) % MOD;
ls.insert(currh);
}
}
for(auto p: ls) ans += mp[p];
++mp[h[i]];
}
mp.clear();
for(int i = n-1; i >= 0; i--) {
set<pair<ll, ll> > ls;
for(int x = 0; x < s[i].length(); x++) {
pair<ll, ll> currh = {s[i][x]-'a' + 1, s[i][x]-'a' + 1};
ls.insert(currh);
for(int y = x+1; y < s[i].length(); y++) {
currh.first = (currh.first * 31 + s[i][y] - 'a' + 1) % MOD;
currh.second = (currh.second * 37 + s[i][y] - 'a' + 1) % MOD;
ls.insert(currh);
}
}
for(auto p: ls) ans += mp[p];
++mp[h[i]];
}
cout << ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |