#include<bits/stdc++.h>
using namespace std;
const int mod1 = 998244353;
const int mod2 = 1e9 + 7;
signed main() {
int n;
cin >> n;
vector <string> s(n);
for(int i = 0; i < n; i++)
{
cin >> s[i];
}
vector <vector <pair <int, int> > > hashes(11);
for(int i = 0; i < n; i++)
{
pair <int, int> hs = make_pair(0, 0);
for(int j = 0; j < s[i].size(); j++)
{
hs.first = (27 * hs.first + s[i][j] - 'a' + 1) % mod1;
hs.second = (27 * hs.second + s[i][j] - 'a' + 1) % mod2;
}
hashes[s[i].size()].push_back(hs);
}
for(int i = 0; i < 11;i++)
{
sort(hashes[i].begin(), hashes[i].end());
}
int ans = 0;
for(int i = 0; i < n; i++)
{
set <pair <int, int> > gethashes;
for(int j = 0; j < s[i].size(); j++)
{
pair <int, int> hs = make_pair(0, 0);
for(int k = j; k < s[i].size(); k++)
{
hs.first = (27 * hs.first + s[i][k] - 'a'+ 1) % mod1;
hs.second = (27 * hs.second + s[i][k] - 'a' + 1) % mod2;
if(gethashes.find(hs) != gethashes.end())
{
continue;
}
gethashes.insert(hs);
int it1 = lower_bound(hashes[k - j + 1].begin(), hashes[k - j + 1].end(), hs) - hashes[k - j + 1].begin();
int it2 = upper_bound(hashes[k - j + 1].begin(), hashes[k - j + 1].end(), hs) - hashes[k - j + 1].begin();
ans += it2 - it1;
}
}
ans--;
}
cout << ans;
return 0;
}
Compilation message
lozinke.cpp: In function 'int main()':
lozinke.cpp:17:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j = 0; j < s[i].size(); j++)
~~^~~~~~~~~~~~~
lozinke.cpp:32:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j = 0; j < s[i].size(); j++)
~~^~~~~~~~~~~~~
lozinke.cpp:35:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int k = j; k < s[i].size(); k++)
~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
10 ms |
384 KB |
Output is correct |
6 |
Correct |
11 ms |
384 KB |
Output is correct |
7 |
Correct |
15 ms |
384 KB |
Output is correct |
8 |
Correct |
16 ms |
640 KB |
Output is correct |
9 |
Correct |
56 ms |
768 KB |
Output is correct |
10 |
Correct |
66 ms |
896 KB |
Output is correct |
11 |
Correct |
88 ms |
1024 KB |
Output is correct |
12 |
Correct |
94 ms |
1152 KB |
Output is correct |
13 |
Correct |
113 ms |
1280 KB |
Output is correct |
14 |
Correct |
139 ms |
1280 KB |
Output is correct |
15 |
Correct |
120 ms |
1280 KB |
Output is correct |
16 |
Correct |
106 ms |
1408 KB |
Output is correct |
17 |
Correct |
40 ms |
1404 KB |
Output is correct |
18 |
Correct |
34 ms |
1400 KB |
Output is correct |
19 |
Correct |
131 ms |
1408 KB |
Output is correct |
20 |
Correct |
92 ms |
1408 KB |
Output is correct |