# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
238172 | 74TrAkToR | Lozinke (COCI17_lozinke) | C++17 | 548 ms | 17504 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;
map < string, int > cnt, d;
string s[20005];
main() {
#ifdef HOME
//freopen("input.txt", "r", stdin);
#endif // HOME
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, ans = 0;
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> s[i];
}
sort(s + 1, s + n + 1, [](string f, string t) {
return (int)f.size() > (int)t.size();
});
for (int i = 1; i <= n; ++i) {
set < string > Q;
ans += cnt[s[i]];
for (int j = 0; j < (int)s[i].size(); ++j) {
string t = "";
for (int pos = j; pos < (int)s[i].size(); ++pos) {
t += s[i][pos];
Q.insert(t);
}
}
for (auto key : Q) cnt[key]++;
d[s[i]]++;
}
for (auto key : d) ans += key.second * (key.second - 1) / 2;
cout << ans << '\n';
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |