#include<bits/stdc++.h>
#define int long long
using namespace std;
int res=0,n,fact[200005];
string t;
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<=20005;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);
adj.push_back("b");
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&&adj[i+1].length()!=adj[i].length())
{
// cout<<"VAILON";
res+=fact[cnt[adj[i]]]/fact[cnt[adj[i]]-2];
}
}
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++)
~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
9856 KB |
Output isn't correct |
2 |
Incorrect |
11 ms |
9856 KB |
Output isn't correct |
3 |
Incorrect |
11 ms |
9984 KB |
Output isn't correct |
4 |
Incorrect |
12 ms |
10112 KB |
Output isn't correct |
5 |
Incorrect |
21 ms |
11512 KB |
Output isn't correct |
6 |
Incorrect |
25 ms |
11380 KB |
Output isn't correct |
7 |
Incorrect |
32 ms |
13168 KB |
Output isn't correct |
8 |
Incorrect |
35 ms |
11904 KB |
Output isn't correct |
9 |
Runtime error |
28 ms |
20464 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |
10 |
Incorrect |
156 ms |
17024 KB |
Output isn't correct |
11 |
Runtime error |
31 ms |
20848 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |
12 |
Incorrect |
398 ms |
26044 KB |
Output isn't correct |
13 |
Incorrect |
240 ms |
23004 KB |
Output isn't correct |
14 |
Runtime error |
35 ms |
21124 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |
15 |
Incorrect |
339 ms |
25936 KB |
Output isn't correct |
16 |
Incorrect |
146 ms |
13100 KB |
Output isn't correct |
17 |
Runtime error |
86 ms |
21040 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |
18 |
Runtime error |
47 ms |
21016 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |
19 |
Incorrect |
253 ms |
27236 KB |
Output isn't correct |
20 |
Runtime error |
36 ms |
21068 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |