Submission #138620

#TimeUsernameProblemLanguageResultExecution timeMemory
138620KCSCLozinke (COCI17_lozinke)C++14
5 / 100
809 ms55800 KiB
#include <bits/stdc++.h> using namespace std; const int DIM = 20005; string str[DIM]; map<string, set<int>> mmp; void solve(int n, int &ans) { mmp.clear(); for (int i = 1; i <= n; ++i) { ans += mmp[str[i]].size(); for (int p1 = 0; p1 < str[i].length(); ++p1) for (int p2 = p1; p2 < str[i].length(); ++p2) mmp[str[i].substr(p1, p2 - p1 + 1)].insert(i); } } inline bool cmp(string s1, string s2) { return s1.length() > s2.length(); } int main(void) { #ifdef HOME freopen("lozinke.in", "r", stdin); freopen("lozinke.out", "w", stdout); #endif int n; cin >> n; for (int i = 1; i <= n; ++i) cin >> str[i]; sort(str + 1, str + n + 1, cmp); int ans = 0; solve(n, ans); for (int i = 1, j = 1; i <= n; i = j) { while (j <= n and str[i] == str[j]) ++j; ans += j - i - 1; } cout << ans; return 0; }

Compilation message (stderr)

lozinke.cpp: In function 'void solve(int, int&)':
lozinke.cpp:13:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int p1 = 0; p1 < str[i].length(); ++p1)
                    ~~~^~~~~~~~~~~~~~~~~
lozinke.cpp:14:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int p2 = p1; p2 < str[i].length(); ++p2)
                      ~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...