#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++)
{
map<string,bool> cur;
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;
ditme.push_back(s);
}
}
}
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)
{
res+=fact[cnt[adj[bump[i]]]]/fact[cnt[adj[bump[i]]]-2];
cur[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:32: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:50:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<bump.size();i++)
~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
11264 KB |
Output is correct |
2 |
Correct |
11 ms |
11264 KB |
Output is correct |
3 |
Correct |
13 ms |
11392 KB |
Output is correct |
4 |
Correct |
12 ms |
11392 KB |
Output is correct |
5 |
Incorrect |
20 ms |
12156 KB |
Output isn't correct |
6 |
Correct |
25 ms |
12204 KB |
Output is correct |
7 |
Incorrect |
30 ms |
13280 KB |
Output isn't correct |
8 |
Correct |
35 ms |
13304 KB |
Output is correct |
9 |
Runtime error |
132 ms |
35576 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |
10 |
Correct |
152 ms |
18644 KB |
Output is correct |
11 |
Runtime error |
222 ms |
43428 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |
12 |
Correct |
377 ms |
27760 KB |
Output is correct |
13 |
Correct |
216 ms |
17320 KB |
Output is correct |
14 |
Runtime error |
325 ms |
63348 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |
15 |
Correct |
409 ms |
27816 KB |
Output is correct |
16 |
Incorrect |
150 ms |
13928 KB |
Output isn't correct |
17 |
Runtime error |
138 ms |
24532 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |
18 |
Runtime error |
80 ms |
28132 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |
19 |
Correct |
274 ms |
22564 KB |
Output is correct |
20 |
Runtime error |
188 ms |
40100 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |