Submission #734118

#TimeUsernameProblemLanguageResultExecution timeMemory
734118JellyTheOctopusLozinke (COCI17_lozinke)C++17
100 / 100
348 ms16716 KiB
#include <bits/stdc++.h> using namespace std; int N; vector<string> arr; map<string, int> freq; int valid(string s) { int len = (int)s.size(); int ans = 0; set<string> unique; for (int i = 0; i < len; i++) { for (int j = i; j < len; j++) { string r = s.substr(i, j-i+1); unique.insert(r); } } for (auto it = unique.begin(); it != unique.end(); it++) { if ((int)(*it).size() == len) { ans += freq[*it]-1; continue; } ans += freq[*it]; } return ans; } int main() { cin >> N; arr.resize(N+1); for (int i = 1; i <= N; i++) { cin >> arr[i]; freq[arr[i]]++; } int ans = 0; for (int i = 1; i <= N; i++) { ans += valid(arr[i]); } cout << ans << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...