Submission #79913

#TimeUsernameProblemLanguageResultExecution timeMemory
79913luckyboyLozinke (COCI17_lozinke)C++14
65 / 100
1085 ms33032 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; map <string,bool> ok; 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[ww]) continue; ok[ww] = 1; ans += dd[ww]; } ++dd[s[i]]; FOR(j,1,temp) FOR(pos,0,temp - j) { string ww = s[i].substr(pos,j); ok[ww] = 0; } } FOR(i,1,n) dd[s[i]] = 0; 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[ww]) continue; ok[ww] = 1; ans += dd[ww]; } ++dd[s[i]]; FOR(j,1,temp) FOR(pos,0,temp - j) { string ww = s[i].substr(pos,j); ok[ww] = 0; } } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...