#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];
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];
}
FOR(j,1,temp)
FOR(pos,0,temp - j)
{
string ww = s[i].substr(pos,j);
ok[i][ww] = 0;
}
++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 (ok[i][ww]) continue;
ok[i][ww] = 1;
ans += dd1[ww];
}
++dd1[s[i]];
}
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
1912 KB |
Output is correct |
2 |
Correct |
4 ms |
1944 KB |
Output is correct |
3 |
Correct |
6 ms |
2216 KB |
Output is correct |
4 |
Correct |
7 ms |
2360 KB |
Output is correct |
5 |
Correct |
41 ms |
4340 KB |
Output is correct |
6 |
Correct |
54 ms |
5620 KB |
Output is correct |
7 |
Correct |
70 ms |
7288 KB |
Output is correct |
8 |
Correct |
108 ms |
10884 KB |
Output is correct |
9 |
Correct |
290 ms |
20384 KB |
Output is correct |
10 |
Correct |
622 ms |
40736 KB |
Output is correct |
11 |
Correct |
565 ms |
40736 KB |
Output is correct |
12 |
Runtime error |
746 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
13 |
Runtime error |
876 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. |
14 |
Runtime error |
889 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. |
15 |
Runtime error |
706 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
16 |
Runtime error |
889 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. |
17 |
Runtime error |
199 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 |
134 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 |
Execution timed out |
1080 ms |
66560 KB |
Time limit exceeded |
20 |
Runtime error |
429 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. |