Submission #116911

#TimeUsernameProblemLanguageResultExecution timeMemory
116911TienDungzLozinke (COCI17_lozinke)C++14
100 / 100
573 ms29884 KiB
#include<bits/stdc++.h> #define int long long using namespace std; int res=0,n; string t; vector<string> adj; unordered_map<string,int> cnt,cnt2; bool cmp (string a,string b) { return a.length()<b.length(); } signed main() { cin>>n; for(int i=1;i<=n;i++) { cin>>t; adj.push_back(t); } sort(adj.begin(),adj.end(),cmp); for(int i=0;i<n;i++) { unordered_map<string,bool> cur; for(int k=1;k<=adj[i].length();k++) { string s; for(int j=0;j<=(adj[i].length()-1)-k+1;j++) { s=adj[i].substr(j,k); if(cnt[s]>=1&&cur[s]==false) { res+=cnt[s]; cur[s]=true; } } } cnt[adj[i]]++; } for(int i=n-1;i>=0;i--) { unordered_map<string,bool> cur; for(int k=1;k<=adj[i].length();k++) { string s; for(int j=0;j<=(adj[i].length()-1)-k+1;j++) { s=adj[i].substr(j,k); if(cur[s]==false) { res+=cnt2[s]; cur[s]=true; } } } cnt2[adj[i]]++; } cout<<res; }

Compilation message (stderr)

lozinke.cpp: In function 'int main()':
lozinke.cpp:24:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int k=1;k<=adj[i].length();k++)
               ~^~~~~~~~~~~~~~~~~
lozinke.cpp:27:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int j=0;j<=(adj[i].length()-1)-k+1;j++)
                ~^~~~~~~~~~~~~~~~~~~~~~~~~
lozinke.cpp:42:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int k=1;k<=adj[i].length();k++)
               ~^~~~~~~~~~~~~~~~~
lozinke.cpp:45:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int j=0;j<=(adj[i].length()-1)-k+1;j++)
                ~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...