# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
887065 | chanhchuong123 | Trener (COCI20_trener) | C++14 | 150 ms | 3740 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define task "MAKELIST"
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int MOD = 1e9 + 7;
int n, k;
int dp[55][1505];
int hh[55][1505][3];
int main() {
ios_base::sync_with_stdio(false); cin.tie(nullptr);
if (fopen(task".inp", "r")) {
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
cin >> n >> k;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= k; ++j) {
string s;
cin >> s;
for (int l = 0, r = max(0, i - 2); r < i; ++l, ++r) {
int hashing = 0;
for (int k = l; k <= r; ++k) {
hashing = 29LL * hashing % MOD;
hashing += s[k] - 'a' + 1;
hashing %= MOD;
}
if (i == 1) {
hh[i][j][2] = hashing;
continue;
}
hh[i][j][l] = hashing;
if (l == 0) {
hashing = 29LL * hashing % MOD;
hashing += s.back() - 'a' + 1;
hashing %= MOD;
hh[i][j][2] = hashing;
}
}
}
}
for (int j = 1; j <= k; ++j) {
dp[1][j] = 1;
}
for (int i = 1; i < n; ++i) {
for (int a = 1; a <= k; ++a) if (dp[i][a]) {
for (int b = 1; b <= k; ++b) if (hh[i][a][2] == hh[i + 1][b][0] || hh[i][a][2] == hh[i + 1][b][1]) {
dp[i + 1][b] += dp[i][a];
if (dp[i + 1][b] >= MOD)
dp[i + 1][b] -= MOD;
}
}
}
int res = 0;
for (int j = 1; j <= k; ++j) {
res += dp[n][j];
if (res >= MOD)
res -= MOD;
}
cout << res;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |