#include<bits/stdc++.h>
#define int long long
using namespace std;
int res=0,n,fact[200005];
string t;
vector<int> bump;
vector<string> adj,ditme;
map<string,int> cnt;
map<string,bool> cur[200005];
bool cmp (string a,string b)
{
return a.length()<b.length();
}
signed main()
{
cin>>n;
fact[0]=1;
for(int i=1;i<=200004;i++)
fact[i]=fact[i-1]*i;
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++)
{
for(int k=1;k<=adj[i].length()-1;k++)
{
string s[20];
for(int j=0;j<=(adj[i].length()-1)-k+1;j++)
{
s[j]=adj[i].substr(j,k);
if(cnt[s[j]]>=1&&cur[i][s[j]]==false)
{
res+=cnt[s[j]];
cur[i][s[j]]=true;
ditme.push_back(s[j]);
}
}
}
cnt[adj[i]]++;
if(cnt[adj[i]]>=2)
{
bump.push_back(i);
}
}
for(int i=0;i<bump.size();i++)
{
if(cur[200002][adj[bump[i]]]==false)
{
res+=fact[cnt[adj[bump[i]]]]/fact[cnt[adj[bump[i]]]-2];
cur[200002][adj[bump[i]]]=true;
}
}
cout<<res;
}
Compilation message
lozinke.cpp: In function 'int main()':
lozinke.cpp:28:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int k=1;k<=adj[i].length()-1;k++)
~^~~~~~~~~~~~~~~~~~~
lozinke.cpp:31: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:48: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 |
Correct |
10 ms |
11264 KB |
Output is correct |
2 |
Correct |
11 ms |
11264 KB |
Output is correct |
3 |
Correct |
12 ms |
11392 KB |
Output is correct |
4 |
Correct |
13 ms |
11520 KB |
Output is correct |
5 |
Incorrect |
23 ms |
12912 KB |
Output isn't correct |
6 |
Correct |
26 ms |
12796 KB |
Output is correct |
7 |
Incorrect |
37 ms |
14576 KB |
Output isn't correct |
8 |
Correct |
37 ms |
13312 KB |
Output is correct |
9 |
Runtime error |
185 ms |
57876 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |
10 |
Correct |
165 ms |
18672 KB |
Output is correct |
11 |
Runtime error |
290 ms |
65536 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |
12 |
Correct |
424 ms |
27888 KB |
Output is correct |
13 |
Correct |
240 ms |
24740 KB |
Output is correct |
14 |
Runtime error |
376 ms |
65536 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |
15 |
Correct |
382 ms |
27788 KB |
Output is correct |
16 |
Incorrect |
150 ms |
14696 KB |
Output isn't correct |
17 |
Runtime error |
89 ms |
24528 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |
18 |
Runtime error |
90 ms |
32744 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |
19 |
Correct |
317 ms |
28956 KB |
Output is correct |
20 |
Runtime error |
265 ms |
65536 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |