# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
116817 | manh9203 | Lozinke (COCI17_lozinke) | C++17 | 1080 ms | 32504 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
bool cmp(string a,string b){
return a.length() < b.length();
}
long long n,ans;
string s[20005];
map<string,int> cnt1,cnt2;
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++) cin>>s[i];
sort(s+1,s+1+n,cmp);
for(int i=1;i<=n;i++){
map<string,bool> check;
for(int len=1;len<=s[i].length();len++){
for(int j=0;j+len-1<s[i].length();j++){
string tmp=s[i].substr(j,len);
if(check[tmp]==0){
ans=ans+cnt1[tmp];
check[tmp]=1;
}
}
}
cnt1[s[i]]++;
}
for(int i=n;i>=1;i--){
map<string,bool> check;
for(int len=1;len<=s[i].length();len++){
for(int j=0;j+len-1<s[i].length();j++){
string tmp=s[i].substr(j,len);
if(check[tmp]==0){
ans=ans+cnt2[tmp];
check[tmp]=1;
}
}
}
cnt2[s[i]]++;
}
cout<<ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |