Submission #200895

#TimeUsernameProblemLanguageResultExecution timeMemory
200895SamAndLozinke (COCI17_lozinke)C++17
100 / 100
112 ms8440 KiB
#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 timeMemoryGrader output
Fetching results...