# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
165737 | 2019-11-28T12:23:44 Z | Sensei | Lozinke (COCI17_lozinke) | C++17 | 1000 ms | 35064 KB |
#include <bits/stdc++.h> using namespace std; const long long P = 53; const long long MOD = 1e9 + 7; const int MAXN = 2e4; long long add (long long x, long long y) { return ((x % MOD) + (y % MOD)) % MOD; } long long mul (long long x, long long y) { return ((x % MOD) * (y % MOD)) % MOD; } // vector<char> st[MAXN + 7]; string st[MAXN + 7]; long long fullhash[MAXN + 7]; // vector<long long> subhashes[MAXN + 7]; set<long long> subhashes[MAXN + 7]; char buff[12]; multiset<long long> fullhashes; int main () { int N; cin >> N; for (int i = 1; i <= N; i++) { // scanf("%s", buff); // for (int j = 0; buff[j] != 0; j++) { // st[i].push_back(buff[j]); // } cin >> st[i]; } for (int i = 1; i <= N; i++) { for (int ss = 0; ss < st[i].size(); ss++) { long long hash = 0; for (int j = ss; j < st[i].size(); j++) { hash = mul(hash, P); hash = add(hash, st[i][j] - 'a' + 1); // subhashes[i].push_back(hash); subhashes[i].insert(hash); if (ss == 0 && j + 1 == st[i].size()) { fullhash[i] = hash; fullhashes.insert(hash); } } } // sort(subhashes[i].begin(), subhashes[i].end()); } long long ans = 0; for (int i = 1; i <= N; i++) { for (long long hash : subhashes[i]) { ans += fullhashes.count(hash); } ans--; } cout << ans << "\n"; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 1912 KB | Output is correct |
2 | Correct | 4 ms | 1912 KB | Output is correct |
3 | Correct | 4 ms | 2040 KB | Output is correct |
4 | Correct | 4 ms | 2040 KB | Output is correct |
5 | Correct | 10 ms | 2808 KB | Output is correct |
6 | Correct | 14 ms | 3704 KB | Output is correct |
7 | Correct | 20 ms | 3960 KB | Output is correct |
8 | Correct | 20 ms | 4996 KB | Output is correct |
9 | Correct | 327 ms | 11256 KB | Output is correct |
10 | Correct | 109 ms | 17284 KB | Output is correct |
11 | Correct | 674 ms | 16376 KB | Output is correct |
12 | Incorrect | 223 ms | 30836 KB | Output isn't correct |
13 | Correct | 238 ms | 30464 KB | Output is correct |
14 | Incorrect | 472 ms | 22864 KB | Output isn't correct |
15 | Incorrect | 255 ms | 33184 KB | Output isn't correct |
16 | Correct | 259 ms | 35064 KB | Output is correct |
17 | Execution timed out | 1074 ms | 12280 KB | Time limit exceeded |
18 | Execution timed out | 1070 ms | 10488 KB | Time limit exceeded |
19 | Correct | 247 ms | 26616 KB | Output is correct |
20 | Execution timed out | 1074 ms | 20216 KB | Time limit exceeded |