Submission #138890

#TimeUsernameProblemLanguageResultExecution timeMemory
138890vladciuperceanuLozinke (COCI17_lozinke)C++14
100 / 100
276 ms2532 KiB
#include <iostream> #include <algorithm> #include <string> #include <set> #include <map> using namespace std; int n,i,sol; string s[20005],aux; set<string> secv; map<string, int> m; int cmp(string a, string b) { if (a.size() != b.size()) return a.size() < b.size(); else return a < b; } int main() { cin >> n; for (i=1; i<=n; i++) cin >> s[i]; sort(s+1, s+n+1, cmp); for (i=1; i<=n; i++) { secv.clear(); secv.insert(s[i]); for (int ind=0; ind<s[i].size(); ind++) for (int lung=1; ind+lung<=s[i].size(); lung++) secv.insert(s[i].substr(ind, lung)); for (set<string>:: iterator it=secv.begin(); it!=secv.end(); it++) if (m.find(*it) != m.end()) sol += m[*it]; if (m.find(s[i]) != m.end()) m[s[i]]++; else m[s[i]] = 1; } for (map<string, int>::iterator it=m.begin(); it!=m.end(); it++) sol += (it->second)*(it->second-1)/2; cout << sol; return 0; }

Compilation message (stderr)

lozinke.cpp: In function 'int main()':
lozinke.cpp:31:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int ind=0; ind<s[i].size(); ind++)
                         ~~~^~~~~~~~~~~~
lozinke.cpp:32:38: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (int lung=1; ind+lung<=s[i].size(); lung++)
                              ~~~~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...