#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
int l=1,n,i,j,k,sol;
string ch[20010],c;
set <string> s;
map <string, int> m;
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>>ch[i];
sort(ch+1,ch+n+1,cmp);
for(i=1;i<=n;i++){
s.clear();
for(j=0;j<ch[i].size();j++){
c.erase(c.begin(),c.end());
for(k=j;k<ch[i].size();k++){
c.push_back(ch[i][k]);
s.insert(c);
}
}
for(set <string>:: iterator it=s.begin();it!=s.end();it++)
if(m.find(*it)!=m.end())
sol+=m[*it];
if(m.find(ch[i])!=m.end())
m[ch[i]]++;
else
m[ch[i]]=1;
}
for(i=2;i<=n;i++){
if(ch[i]==ch[i-1])
l++;
else
l=1;
sol+=l-1;
}
cout<<sol;
return 0;
}
Compilation message
lozinke.cpp: In function 'int main()':
lozinke.cpp:24:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(j=0;j<ch[i].size();j++){
~^~~~~~~~~~~~~
lozinke.cpp:26:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(k=j;k<ch[i].size();k++){
~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 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 |
18 ms |
1144 KB |
Output is correct |
7 |
Correct |
21 ms |
1144 KB |
Output is correct |
8 |
Correct |
26 ms |
1144 KB |
Output is correct |
9 |
Correct |
98 ms |
1496 KB |
Output is correct |
10 |
Correct |
130 ms |
1528 KB |
Output is correct |
11 |
Correct |
157 ms |
1912 KB |
Output is correct |
12 |
Correct |
250 ms |
1912 KB |
Output is correct |
13 |
Correct |
252 ms |
2096 KB |
Output is correct |
14 |
Correct |
217 ms |
2424 KB |
Output is correct |
15 |
Correct |
270 ms |
2168 KB |
Output is correct |
16 |
Correct |
198 ms |
1404 KB |
Output is correct |
17 |
Correct |
78 ms |
1272 KB |
Output is correct |
18 |
Correct |
62 ms |
1272 KB |
Output is correct |
19 |
Correct |
223 ms |
2132 KB |
Output is correct |
20 |
Correct |
132 ms |
1400 KB |
Output is correct |