# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
391678 | 2021-04-19T14:08:20 Z | phathnv | Trener (COCI20_trener) | C++11 | 61 ms | 8216 KB |
#include <bits/stdc++.h> #define mp make_pair #define X first #define Y second #define taskname "TRENER" using namespace std; typedef long long ll; typedef pair <int, int> ii; const int N = 51; const int K = 1501; const int base = 163; const int MOD = 1e9 + 7; int n, k; char a[N][K][N]; ll hashed[N][K][3], pw[N]; int dp[N][K]; void readInput(){ scanf("%d %d", &n, &k); for(int i = 1; i <= n; i++) for(int j = 1; j <= k; j++) scanf("%s", a[i][j] + 1); } void prepare(){ pw[0] = 1; for(int i = 1; i <= n; i++) pw[i] = pw[i - 1] * base; for(int i = 1; i <= n; i++) for(int j = 1; j <= k; j++){ ll val = 0; for(int p = 1; p < i; p++) val = val * base + a[i][j][p]; hashed[i][j][0] = val; val = val * base + a[i][j][i]; hashed[i][j][1] = val - a[i][j][1] * pw[i - 1]; hashed[i][j][2] = val; } } void add(int &x, const int &y){ x += y; x -= (x >= MOD) * MOD; } void solve(){ for(int i = 1; i <= k; i++) dp[1][i] = 1; for(int i = 2; i <= n; i++){ map <ll, int> d; for(int j = 1; j <= k; j++) add(d[hashed[i - 1][j][2]], dp[i - 1][j]); for(int j = 1; j <= k; j++){ add(dp[i][j], d[hashed[i][j][0]]); if (hashed[i][j][0] != hashed[i][j][1]) add(dp[i][j], d[hashed[i][j][1]]); } } int res = 0; for(int i = 1; i <= k; i++) add(res, dp[n][i]); printf("%d", res); } int main(){ readInput(); prepare(); solve(); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 332 KB | Output is correct |
2 | Correct | 1 ms | 332 KB | Output is correct |
3 | Correct | 1 ms | 332 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 1356 KB | Output is correct |
2 | Correct | 4 ms | 1356 KB | Output is correct |
3 | Correct | 4 ms | 1356 KB | Output is correct |
4 | Correct | 2 ms | 1356 KB | Output is correct |
5 | Correct | 4 ms | 1352 KB | Output is correct |
6 | Correct | 4 ms | 1356 KB | Output is correct |
7 | Correct | 2 ms | 1356 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 332 KB | Output is correct |
2 | Correct | 1 ms | 332 KB | Output is correct |
3 | Correct | 1 ms | 332 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 4 ms | 1356 KB | Output is correct |
6 | Correct | 4 ms | 1356 KB | Output is correct |
7 | Correct | 4 ms | 1356 KB | Output is correct |
8 | Correct | 2 ms | 1356 KB | Output is correct |
9 | Correct | 4 ms | 1352 KB | Output is correct |
10 | Correct | 4 ms | 1356 KB | Output is correct |
11 | Correct | 2 ms | 1356 KB | Output is correct |
12 | Correct | 53 ms | 8124 KB | Output is correct |
13 | Correct | 61 ms | 8216 KB | Output is correct |
14 | Correct | 54 ms | 8132 KB | Output is correct |
15 | Correct | 52 ms | 8216 KB | Output is correct |
16 | Correct | 21 ms | 8012 KB | Output is correct |
17 | Correct | 46 ms | 8068 KB | Output is correct |
18 | Correct | 46 ms | 8132 KB | Output is correct |
19 | Correct | 46 ms | 8192 KB | Output is correct |
20 | Correct | 47 ms | 8188 KB | Output is correct |
21 | Correct | 46 ms | 8132 KB | Output is correct |
22 | Correct | 22 ms | 8132 KB | Output is correct |