#include<bits/stdc++.h>
#define int long long
using namespace std;
int res=0,n;
string t;
vector<int> bump;
vector<string> adj;
unordered_map<string,int> cnt;
bool cmp (string a,string b)
{
return a.length()<b.length();
}
signed main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>t;
adj.push_back(t);
}
sort(adj.begin(),adj.end(),cmp);
for(int i=0;i<n;i++)
{
unordered_map<string,bool> cur;
for(int k=1;k<=adj[i].length();k++)
{
string s;
for(int j=0;j<=(adj[i].length()-1)-k+1;j++)
{
s=adj[i].substr(j,k);
if(cnt[s]>=1&&cur[s]==false)
{
res+=cnt[s];
cur[s]=true;
}
}
}
cnt[adj[i]]++;
if(cnt[adj[i]]>=2)
{
bump.push_back(i);
}
}
map<string,bool> cur;
for(int i=0;i<bump.size();i++)
{
if(cur[adj[bump[i]]]==false)
{
int a=1,b=1;
for(int j=1;j<=cnt[adj[bump[i]]];j++)
{
a=a*j;
if(j==cnt[adj[bump[i]]]-2) b=a;
}
res+=a/b;
cur[adj[bump[i]]]=true;
}
}
cout<<res;
}
Compilation message
lozinke.cpp: In function 'int main()':
lozinke.cpp:25:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int k=1;k<=adj[i].length();k++)
~^~~~~~~~~~~~~~~~~
lozinke.cpp:28:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0;j<=(adj[i].length()-1)-k+1;j++)
~^~~~~~~~~~~~~~~~~~~~~~~~~
lozinke.cpp:45:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<bump.size();i++)
~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
2 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
3 |
Incorrect |
2 ms |
356 KB |
Output isn't correct |
4 |
Incorrect |
3 ms |
384 KB |
Output isn't correct |
5 |
Incorrect |
8 ms |
776 KB |
Output isn't correct |
6 |
Incorrect |
9 ms |
768 KB |
Output isn't correct |
7 |
Incorrect |
13 ms |
1536 KB |
Output isn't correct |
8 |
Incorrect |
13 ms |
2176 KB |
Output isn't correct |
9 |
Runtime error |
62 ms |
4592 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |
10 |
Incorrect |
93 ms |
7232 KB |
Output isn't correct |
11 |
Runtime error |
92 ms |
8308 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |
12 |
Incorrect |
226 ms |
15496 KB |
Output isn't correct |
13 |
Incorrect |
98 ms |
3052 KB |
Output isn't correct |
14 |
Runtime error |
194 ms |
27912 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |
15 |
Incorrect |
210 ms |
15520 KB |
Output isn't correct |
16 |
Incorrect |
84 ms |
1528 KB |
Output isn't correct |
17 |
Runtime error |
74 ms |
2536 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |
18 |
Runtime error |
66 ms |
2540 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |
19 |
Incorrect |
128 ms |
8424 KB |
Output isn't correct |
20 |
Runtime error |
97 ms |
2504 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |