Submission #97756

#TimeUsernameProblemLanguageResultExecution timeMemory
97756dalgerokLozinke (COCI17_lozinke)C++17
95 / 100
1031 ms15544 KiB
#include<bits/stdc++.h> using namespace std; struct super_hash{ size_t operator()(string x)const{ unsigned long long cur = 0, p = 1; for(auto it : x){ cur += p * it; p *= 59; } return cur; } }; unordered_map < string, int, super_hash > q; inline void add(string &s){ unordered_map < string, int, super_hash > used; for(int i = 0; i < (int)s.size(); i++){ string t; for(int j = i; j < (int)s.size(); j++){ t += s[j]; if(used.find(t) == used.end()){ q[t] += 1; used[t] = true; } } } } inline void del(string &s){ unordered_map < string, int, super_hash > used; for(int i = 0; i < (int)s.size(); i++){ string t; for(int j = i; j < (int)s.size(); j++){ t += s[j]; if(used.find(t) == used.end()){ q[t] -= 1; used[t] = false; } } } } int main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); int n; cin >> n; string s[n]; for(int i = 0; i < n; i++){ cin >> s[i]; add(s[i]); } int ans = 0; for(int i = 0; i < n; i++){ del(s[i]); ans += q[s[i]]; add(s[i]); } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...