Submission #79937

#TimeUsernameProblemLanguageResultExecution timeMemory
79937luckyboyLozinke (COCI17_lozinke)C++14
45 / 100
801 ms66560 KiB
#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 timeMemoryGrader output
Fetching results...