# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
832125 | 2023-08-21T02:05:05 Z | vjudge1 | Lozinke (COCI17_lozinke) | C++14 | 74 ms | 12268 KB |
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ull; const int P = 1e9 + 7; const int N = 2e4 + 10; const int M = 11; int read() { int num = 0, flag = 1; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) if (ch == '-') flag = -1; for (; isdigit(ch); ch = getchar()) num = (num << 3) + (num << 1) + ch - '0'; return num * flag; } string readline() { string s; char ch = getchar(); while (!isalpha(ch)) ch = getchar(); for (; ch > 13; ch = getchar()) s.push_back(ch); return s; } string pwd[N]; ull pw[N]; ull h[N][M]; unordered_set<ull> sub; unordered_map<ull, int> res; int main() { pw[0] = 1; for (int i = 1; i < N; ++i) pw[i] = pw[i - 1] * P; int n = read(); for (int i = 0; i < n; ++i) { pwd[i] = readline(); sub.clear(); h[i][0] = pwd[i][0]; for (int k = 1; k < pwd[i].size(); ++k) h[i][k] = h[i][k - 1] * P + pwd[i][k]; for (int r = 0; r < pwd[i].size(); ++r) sub.insert(h[i][r]); for (int l = 1; l < pwd[i].size(); ++l) for (int r = l; r < pwd[i].size(); ++r) sub.insert(h[i][r] - h[i][l - 1] * pw[r - l + 1]); for (ull k : sub) ++res[k]; } int ans = 0; for (int i = 0; i < n; ++i) ans += res[h[i][pwd[i].size() - 1]]; printf("%d\n", ans - n); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 1108 KB | Output is correct |
2 | Correct | 1 ms | 1100 KB | Output is correct |
3 | Correct | 1 ms | 1108 KB | Output is correct |
4 | Correct | 1 ms | 1108 KB | Output is correct |
5 | Correct | 3 ms | 1364 KB | Output is correct |
6 | Correct | 4 ms | 1364 KB | Output is correct |
7 | Correct | 5 ms | 1876 KB | Output is correct |
8 | Correct | 7 ms | 2388 KB | Output is correct |
9 | Correct | 21 ms | 3016 KB | Output is correct |
10 | Correct | 33 ms | 6660 KB | Output is correct |
11 | Correct | 27 ms | 4648 KB | Output is correct |
12 | Correct | 72 ms | 11720 KB | Output is correct |
13 | Correct | 45 ms | 3956 KB | Output is correct |
14 | Correct | 62 ms | 12268 KB | Output is correct |
15 | Correct | 74 ms | 12108 KB | Output is correct |
16 | Correct | 52 ms | 3004 KB | Output is correct |
17 | Correct | 23 ms | 2888 KB | Output is correct |
18 | Correct | 17 ms | 2872 KB | Output is correct |
19 | Correct | 46 ms | 7288 KB | Output is correct |
20 | Correct | 27 ms | 2948 KB | Output is correct |