# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
472800 | 2021-09-14T10:53:16 Z | AbdoMo | Lozinke (COCI17_lozinke) | C++17 | 345 ms | 17008 KB |
#include<bits/stdc++.h> #define int long long #define ll long long #define pb push_back const int mod = 1e9+7; using namespace std; bool comp(string a,string b) { if(a.size()==b.size()) { return a<b; } return a.size()<b.size(); } void solve(){ int n; cin>>n; vector<string>v; unordered_map<string,int>freq; unordered_map<string,int>freqsb; for(int i=0;i<n;i++) { string s; cin>>s; set<string>ts; for(int j=0;j<s.size();j++) { for(int k=1;k+j<=s.size();k++) { ts.insert(s.substr(j,k)); } } for(auto it=ts.begin();it!=ts.end();it++) { freqsb[*it]++; } freq[s]++; v.pb(s); } sort(v.begin(),v.end(),comp); int ans=0; int c=1; for(int i=0;i<n;i+=freq[v[i]]) { int x=freq[v[i]]; ans+=x*(x-1); ans+=x*(freqsb[v[i]]-x); } cout<<ans<<endl; /* */ } int32_t main(){ int t=1; ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); //cin>>t; while(t--){solve();} return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 332 KB | Output is correct |
4 | Correct | 2 ms | 332 KB | Output is correct |
5 | Correct | 7 ms | 648 KB | Output is correct |
6 | Correct | 15 ms | 740 KB | Output is correct |
7 | Correct | 15 ms | 1484 KB | Output is correct |
8 | Correct | 25 ms | 2264 KB | Output is correct |
9 | Correct | 60 ms | 2828 KB | Output is correct |
10 | Correct | 132 ms | 8408 KB | Output is correct |
11 | Correct | 112 ms | 4928 KB | Output is correct |
12 | Correct | 292 ms | 16716 KB | Output is correct |
13 | Correct | 173 ms | 3640 KB | Output is correct |
14 | Correct | 218 ms | 16928 KB | Output is correct |
15 | Correct | 345 ms | 17008 KB | Output is correct |
16 | Correct | 190 ms | 1592 KB | Output is correct |
17 | Correct | 76 ms | 1348 KB | Output is correct |
18 | Correct | 58 ms | 1472 KB | Output is correct |
19 | Correct | 198 ms | 9400 KB | Output is correct |
20 | Correct | 100 ms | 1688 KB | Output is correct |