#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for (int i = (a); i >= (b); --i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define maxc 1000000007
#define maxn 20005
#define maxm 500005
#define pii pair <int,int>
#define Task "Lozinke"
using namespace std;
int n;
string s[maxn];
map <string,int> dd,dd1;
map <string,bool> ok[maxn],ok1[maxn];
long long ans;
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//freopen(Task".inp", "r",stdin);
//freopen(Task".out", "w",stdout);
cin >> n;
FOR(i,1,n)
{
cin >> s[i];
int temp = s[i].size();
FOR(j,1,temp)
FOR(pos,0,temp - j)
{
string ww = s[i].substr(pos,j);
if (ok[i][ww]) continue;
ok[i][ww] = 1;
ans += dd[ww];
}
++dd[s[i]];
}
FORD(i,n,1)
{
int temp = s[i].size();
FOR(j,1,temp)
FOR(pos,0,temp - j)
{
string ww = s[i].substr(pos,j);
if (ok1[i][ww]) continue;
ok1[i][ww] = 1;
ans += dd1[ww];
}
++dd1[s[i]];
FOR(j,1,temp)
FOR(pos,0,temp - j)
{
string ww = s[i].substr(pos,j);
ok1[i][ww] = 0;
}
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2936 KB |
Output is correct |
2 |
Correct |
4 ms |
3028 KB |
Output is correct |
3 |
Correct |
8 ms |
3344 KB |
Output is correct |
4 |
Correct |
7 ms |
3560 KB |
Output is correct |
5 |
Correct |
47 ms |
6816 KB |
Output is correct |
6 |
Correct |
59 ms |
9304 KB |
Output is correct |
7 |
Correct |
75 ms |
11540 KB |
Output is correct |
8 |
Correct |
119 ms |
16660 KB |
Output is correct |
9 |
Correct |
305 ms |
35860 KB |
Output is correct |
10 |
Runtime error |
685 ms |
66452 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |
11 |
Runtime error |
546 ms |
66452 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |
12 |
Runtime error |
614 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
13 |
Runtime error |
598 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
14 |
Runtime error |
568 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
15 |
Runtime error |
801 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
16 |
Runtime error |
529 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
17 |
Runtime error |
226 ms |
66560 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |
18 |
Runtime error |
158 ms |
66560 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |
19 |
Runtime error |
638 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
20 |
Runtime error |
462 ms |
66560 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |