# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
887065 | chanhchuong123 | Trener (COCI20_trener) | C++14 | 150 ms | 3740 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
컴파일 시 표준 에러 (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... |