# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
938527 | 2024-03-05T08:54:55 Z | sapientsapiens | Lozinke (COCI17_lozinke) | C++14 | 294 ms | 16720 KB |
/* At Most 10 lowercase letters of the English Alphabet -> We should think in terms of the alphabet and the orientation What is the fastest, most efficient way to check if one string is a subset of another Of course there isn't some magical way to compare two strings. The solution: Don't compare two strings. Have a frequency array of how many each substring appears */ #include <iostream> #include <string> #include <utility> #include <string> #include <map> using namespace std; int n; string str[20005]; map<string, int> mp; int main() { cin >> n; for(int i = 0; i < n; i++) { cin >> str[i]; map<string, int> temp; for(int j = 0; j < str[i].size(); j++) { for(int k = j; k < str[i].size(); k++) { string exp; for(int l = j; l <= k; l++) { exp += str[i][l]; } temp[exp] = 1; } } for (const auto &p : temp) { // Now you can access the key using p.first and the value using p.second mp[p.first] ++; // Example operation } } int ans = 0; for(int i = 0; i < n; i++) { ans += mp[str[i]] -1; } cout << ans; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 1016 KB | Output is correct |
2 | Correct | 1 ms | 860 KB | Output is correct |
3 | Correct | 1 ms | 860 KB | Output is correct |
4 | Correct | 1 ms | 1116 KB | Output is correct |
5 | Correct | 7 ms | 1372 KB | Output is correct |
6 | Correct | 11 ms | 1172 KB | Output is correct |
7 | Correct | 14 ms | 2028 KB | Output is correct |
8 | Correct | 24 ms | 2908 KB | Output is correct |
9 | Correct | 58 ms | 2824 KB | Output is correct |
10 | Correct | 120 ms | 7788 KB | Output is correct |
11 | Correct | 99 ms | 4432 KB | Output is correct |
12 | Correct | 270 ms | 16720 KB | Output is correct |
13 | Correct | 188 ms | 2640 KB | Output is correct |
14 | Correct | 185 ms | 14860 KB | Output is correct |
15 | Correct | 294 ms | 16416 KB | Output is correct |
16 | Correct | 181 ms | 1204 KB | Output is correct |
17 | Correct | 50 ms | 856 KB | Output is correct |
18 | Correct | 35 ms | 856 KB | Output is correct |
19 | Correct | 185 ms | 8472 KB | Output is correct |
20 | Correct | 102 ms | 1368 KB | Output is correct |