#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int N = 51;
const int K = 1510;
const int MOD = (int)1e9 + 7;
const int mod = 998244353;
const int AL = 26;
int h1[N][K];
int h2[N][K];
int hh[N][K];
int dp[N][K];
int main(){
fastIO;
int n, k;
cin >> n >> k;
string cur;
int sum, pwr;
for(int i = 1 ; i <= n; i ++ ){
for(int j = 0 ; j < k ; j ++ ){
cin >> cur;
sum = 0, pwr = 1;
for(int f = 0; f < i; f ++ ){
sum = (sum + ((cur[f] - 'a' + 1) * 1ll * pwr) % mod) % mod;
pwr = (pwr * 1ll * AL) % mod;
}
hh[i][j] = sum;
sum = 0, pwr = 1;
for(int f = 0; f < i - 1; f ++ ){
sum = (sum + ((cur[f] - 'a' + 1) * 1ll * pwr) % mod) % mod;
pwr = (pwr * 1ll * AL) % mod;
}
h1[i][j] = sum;
sum = 0, pwr = 1;
for(int f = 1; f < i; f ++ ){
sum = (sum + ((cur[f] - 'a' + 1) * 1ll * pwr) % mod) % mod;
pwr = (pwr * 1ll * AL) % mod;
}
h2[i][j] = sum;
}
}
for(int i = 0 ; i < k ; i ++ ) dp[n][i] = 1;
for(int i = n - 1; i >= 1; i -- ){
for(int j = 0 ; j < k ; j ++ ){
for(int x = 0; x < k ; x ++ ){
if(hh[i][j] == h1[i + 1][x] || hh[i][j] == h2[i + 1][x]){
dp[i][j]=(dp[i][j]+dp[i+1][x])%MOD;
}
}
}
}
int ans = 0;
for(int i = 0 ; i < k ; i ++ ) ans = (ans + dp[1][i]) % MOD;
cout << ans << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
1280 KB |
Output is correct |
2 |
Correct |
9 ms |
1408 KB |
Output is correct |
3 |
Correct |
9 ms |
1408 KB |
Output is correct |
4 |
Correct |
11 ms |
1280 KB |
Output is correct |
5 |
Correct |
9 ms |
1280 KB |
Output is correct |
6 |
Correct |
9 ms |
1408 KB |
Output is correct |
7 |
Correct |
11 ms |
1408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
9 ms |
1280 KB |
Output is correct |
6 |
Correct |
9 ms |
1408 KB |
Output is correct |
7 |
Correct |
9 ms |
1408 KB |
Output is correct |
8 |
Correct |
11 ms |
1280 KB |
Output is correct |
9 |
Correct |
9 ms |
1280 KB |
Output is correct |
10 |
Correct |
9 ms |
1408 KB |
Output is correct |
11 |
Correct |
11 ms |
1408 KB |
Output is correct |
12 |
Correct |
154 ms |
3448 KB |
Output is correct |
13 |
Correct |
152 ms |
3448 KB |
Output is correct |
14 |
Correct |
160 ms |
3576 KB |
Output is correct |
15 |
Correct |
151 ms |
3516 KB |
Output is correct |
16 |
Correct |
817 ms |
3516 KB |
Output is correct |
17 |
Correct |
166 ms |
3608 KB |
Output is correct |
18 |
Correct |
175 ms |
3476 KB |
Output is correct |
19 |
Correct |
174 ms |
3472 KB |
Output is correct |
20 |
Correct |
170 ms |
3576 KB |
Output is correct |
21 |
Correct |
166 ms |
3448 KB |
Output is correct |
22 |
Correct |
801 ms |
3576 KB |
Output is correct |