# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
200895 | SamAnd | Lozinke (COCI17_lozinke) | C++17 | 112 ms | 8440 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int N = 20004;
int n;
string a[N];
int z;
int t[N * 11][26];
int q[N * 11];
int main()
{
cin >> n;
for (int i = 0; i < n; ++i)
cin >> a[i];
for (int i = 0; i < n; ++i)
{
int m = a[i].size();
int pos = 0;
for (int j = 0; j < m; ++j)
{
if (!t[pos][a[i][j] - 'a'])
t[pos][a[i][j] - 'a'] = ++z;
pos = t[pos][a[i][j] - 'a'];
}
++q[pos];
}
long long ans = 0;
for (int i = 0; i < n; ++i)
{
int m = a[i].size();
set<int> s;
for (int l = 0; l < m; ++l)
{
int pos = 0;
for (int j = l; j < m; ++j)
{
if (!t[pos][a[i][j] - 'a'])
break;
pos = t[pos][a[i][j] - 'a'];
if (s.find(pos) == s.end())
ans += q[pos];
s.insert(pos);
}
}
--ans;
}
cout << ans << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |