#include <iostream>
#include <map>
#include <string>
#include <set>
#include <algorithm>
using namespace std;
map<string, int> m;
int n, i, sol;
string s[20010], sc;
set<string> st;
int cmp(string a, string b) {
if (a.size() != b.size())
return a.size()<b.size();
else
return a<b;
}
int main () {
cin>>n;
for (i=1;i<=n;i++)
cin>>s[i];
sort(s+1,s+n+1,cmp);
for (i=1;i<=n;i++) {
st.clear();
for (int j=0;j<s[i].size();j++) {
sc.erase(sc.begin(), sc.end());
for (int k=j;k<s[i].size();k++) {
sc.push_back(s[i][k]);
st.insert(sc);
}
}
for (set<string>:: iterator it = st.begin(); it != st.end(); it++) {
if (m.find(*it) != m.end())
sol += m[*it];
}
if (m.find(s[i]) == m.end())
m[s[i]] = 1;
else
m[s[i]]++;
}
int L = 1;
for (i=2;i<=n;i++) {
if (s[i] == s[i-1])
L++;
else
L = 1;
sol += L-1;
}
cout<<sol;
}
Compilation message
lozinke.cpp: In function 'int main()':
lozinke.cpp:26:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j=0;j<s[i].size();j++) {
~^~~~~~~~~~~~
lozinke.cpp:28:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int k=j;k<s[i].size();k++) {
~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1016 KB |
Output is correct |
2 |
Correct |
3 ms |
888 KB |
Output is correct |
3 |
Correct |
3 ms |
1016 KB |
Output is correct |
4 |
Correct |
4 ms |
1016 KB |
Output is correct |
5 |
Correct |
12 ms |
1016 KB |
Output is correct |
6 |
Correct |
19 ms |
1016 KB |
Output is correct |
7 |
Correct |
21 ms |
1016 KB |
Output is correct |
8 |
Correct |
26 ms |
1016 KB |
Output is correct |
9 |
Correct |
97 ms |
1596 KB |
Output is correct |
10 |
Correct |
135 ms |
1528 KB |
Output is correct |
11 |
Correct |
157 ms |
1788 KB |
Output is correct |
12 |
Correct |
256 ms |
2032 KB |
Output is correct |
13 |
Correct |
253 ms |
2296 KB |
Output is correct |
14 |
Correct |
219 ms |
2424 KB |
Output is correct |
15 |
Correct |
269 ms |
2168 KB |
Output is correct |
16 |
Correct |
208 ms |
1292 KB |
Output is correct |
17 |
Correct |
77 ms |
1144 KB |
Output is correct |
18 |
Correct |
62 ms |
1144 KB |
Output is correct |
19 |
Correct |
223 ms |
2168 KB |
Output is correct |
20 |
Correct |
138 ms |
1296 KB |
Output is correct |