#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
const long long MOD = 998244353;
const long long INF = 1e18;
int nx[4] = {0, 0, -1, 1};
int ny[4] = {1, -1, 0, 0};
ll my_rand(ll l, ll r)
{
srand(chrono::steady_clock::now().time_since_epoch().count());
ll len = r-l;
ll a = rand()%len;
ll b = rand()%len;
ll res = ((((a%len)*((RAND_MAX+1)%len))%len) + (b%len))%len;
if(res<l)
res +=l;
return res;
}
bool substring(string sub, string s)
{
for(int i = 0; i+int(sub.length())-1<int(s.length()); i++)
{
bool flag = true;
for(int j = 0; j<int(sub.length()); j++)
{
if(sub[j]!=s[i+j])
{
flag = false;
break;
}
}
if(flag)
return true;
}
return false;
}
bool compare(string &a, string &b)
{
int lena = int(a.length());
int lenb = int(b.length());
if(lena==lenb)
return a<=b;
return lena<lenb;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll n;
cin >> n;
vector<string> arr;
for(int i = 0; i<n; i++)
{
string s;
cin >> s;
arr.pb(s);
}
sort(arr.begin(), arr.end(), compare);
ll res = 0;
for(int i = 0; i<n; i++)
{
for(int j = 0; j<n; j++)
{
if(i==j)
continue;
if(substring(arr[i], arr[j]))
res++;
}
}
cout << res << endl;
return 0;
}
Compilation message
lozinke.cpp: In function 'long long int my_rand(long long int, long long int)':
lozinke.cpp:24:35: warning: integer overflow in expression of type 'int' results in '-2147483648' [-Woverflow]
24 | ll res = ((((a%len)*((RAND_MAX+1)%len))%len) + (b%len))%len;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
308 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
5 ms |
332 KB |
Output is correct |
5 |
Correct |
25 ms |
316 KB |
Output is correct |
6 |
Correct |
58 ms |
424 KB |
Output is correct |
7 |
Correct |
105 ms |
436 KB |
Output is correct |
8 |
Correct |
92 ms |
460 KB |
Output is correct |
9 |
Runtime error |
5 ms |
1356 KB |
Execution killed with signal 11 |
10 |
Execution timed out |
1075 ms |
968 KB |
Time limit exceeded |
11 |
Runtime error |
7 ms |
1740 KB |
Execution killed with signal 11 |
12 |
Execution timed out |
1081 ms |
1100 KB |
Time limit exceeded |
13 |
Execution timed out |
1079 ms |
1612 KB |
Time limit exceeded |
14 |
Runtime error |
7 ms |
2120 KB |
Execution killed with signal 11 |
15 |
Execution timed out |
1026 ms |
1600 KB |
Time limit exceeded |
16 |
Runtime error |
13 ms |
2136 KB |
Execution killed with signal 11 |
17 |
Runtime error |
4 ms |
2168 KB |
Execution killed with signal 11 |
18 |
Runtime error |
5 ms |
2160 KB |
Execution killed with signal 11 |
19 |
Execution timed out |
1073 ms |
1612 KB |
Time limit exceeded |
20 |
Runtime error |
13 ms |
2120 KB |
Execution killed with signal 11 |