# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
223220 |
2020-04-15T05:32:28 Z |
lyc |
Trener (COCI20_trener) |
C++14 |
|
528 ms |
6644 KB |
#include <bits/stdc++.h>
using namespace std;
#define SZ(x) (int)(x).size()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for (int i=(a);i>=(b);--i)
const int MX_N = 55;
const int MX_K = 1505;
const int MOD = 1e9+7;
const int P = 101, Q = 1e9+7;
int N, K;
string S[MX_N][MX_K];
pair<int,int> h[MX_N][MX_K];
int dp[MX_N][MX_K];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> N >> K;
FOR(i,1,N){
FOR(j,1,K) cin >> S[i][j];
}
FOR(j,1,K) {
int cur = 0;
FOR(k,0,N-2) {
cur = ((1LL*cur*P) % Q + S[N][j][k]-'a') % Q;
}
h[N][j].first = cur;
cur = 0;
FOR(k,1,N-1) {
cur = ((1LL*cur*P) % Q + S[N][j][k]-'a') % Q;
}
h[N][j].second = cur;
dp[N][j] = 1;
}
RFOR(i,N-1,1){
FOR(j,1,K){
dp[i][j] = 0;
int cur = 0;
FOR(k,0,i-2) {
cur = ((1LL*cur*P) % Q + S[i][j][k]-'a') % Q;
}
h[i][j].first = cur;
cur = ((1LL*cur*P) % Q + S[i][j][i-1]-'a') % Q;
//cout << "i j " << i << " " << j << " :: " << cur << endl;
FOR(k,1,K) {
if (cur == h[i+1][k].first || cur == h[i+1][k].second) {
//cout << i << " " << j << " :: " << i+1 << " " << k << endl;
dp[i][j] += dp[i+1][k];
if (dp[i][j] >= MOD) dp[i][j] -= MOD;
}
}
cur = 0;
FOR(k,1,i-1) {
cur = ((1LL*cur*P) % Q + S[i][j][k]-'a') % Q;
}
h[i][j].second = cur;
}
}
int ans = 0;
FOR(i,1,K){
ans += dp[1][i];
if (ans >= MOD) ans -= MOD;
}
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2944 KB |
Output is correct |
2 |
Correct |
6 ms |
2944 KB |
Output is correct |
3 |
Correct |
6 ms |
2944 KB |
Output is correct |
4 |
Correct |
6 ms |
2944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
3584 KB |
Output is correct |
2 |
Correct |
10 ms |
3584 KB |
Output is correct |
3 |
Correct |
11 ms |
3584 KB |
Output is correct |
4 |
Correct |
12 ms |
3584 KB |
Output is correct |
5 |
Correct |
10 ms |
3584 KB |
Output is correct |
6 |
Correct |
11 ms |
3584 KB |
Output is correct |
7 |
Correct |
12 ms |
3584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2944 KB |
Output is correct |
2 |
Correct |
6 ms |
2944 KB |
Output is correct |
3 |
Correct |
6 ms |
2944 KB |
Output is correct |
4 |
Correct |
6 ms |
2944 KB |
Output is correct |
5 |
Correct |
11 ms |
3584 KB |
Output is correct |
6 |
Correct |
10 ms |
3584 KB |
Output is correct |
7 |
Correct |
11 ms |
3584 KB |
Output is correct |
8 |
Correct |
12 ms |
3584 KB |
Output is correct |
9 |
Correct |
10 ms |
3584 KB |
Output is correct |
10 |
Correct |
11 ms |
3584 KB |
Output is correct |
11 |
Correct |
12 ms |
3584 KB |
Output is correct |
12 |
Correct |
195 ms |
6520 KB |
Output is correct |
13 |
Correct |
190 ms |
6520 KB |
Output is correct |
14 |
Correct |
203 ms |
6644 KB |
Output is correct |
15 |
Correct |
188 ms |
6520 KB |
Output is correct |
16 |
Correct |
520 ms |
6520 KB |
Output is correct |
17 |
Correct |
214 ms |
6612 KB |
Output is correct |
18 |
Correct |
210 ms |
6520 KB |
Output is correct |
19 |
Correct |
207 ms |
6612 KB |
Output is correct |
20 |
Correct |
205 ms |
6520 KB |
Output is correct |
21 |
Correct |
204 ms |
6520 KB |
Output is correct |
22 |
Correct |
528 ms |
6520 KB |
Output is correct |