#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<ll, ll>;
#define foru(i, l, r) for(int i=(l); i<=(r); ++i)
#define ford(i, l, r) for(int i=(l); i>=(r); --i)
#define fore(x, v) for(auto &x : v)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define file "input"
template<class T> bool minimize(T &a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> bool maximize(T &a, T b) { if (a < b) { a = b; return 1; } return 0; }
void setIO() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if (fopen(file".inp", "r")) {
freopen(file".inp", "r", stdin);
freopen(file".out", "w", stdout);
}
}
const int MOD = 1e9+7, B = 256;
const int N = 51, K = 1501;
int n, k, dp[N][K];
int one[N][K], two[N][K];
string s[N][K];
int mul(int a, int b) {
return 1LL * a * b % MOD;
}
void add(int &a, int b) {
a += b;
if (a >= MOD) a -= MOD;
}
int main() {
setIO();
cin >> n >> k;
foru(i, 1, n) foru(j, 1, k) {
cin >> s[i][j];
foru(c, 0, i-2) one[i][j] = (1LL * one[i][j] * B % MOD + s[i][j][c]) % MOD;
foru(c, 1, i-1) two[i][j] = (1LL * two[i][j] * B % MOD + s[i][j][c]) % MOD;
}
foru(i, 1, k) dp[1][i] = 1;
foru(i, 1, n) {
foru(j, 1, k) if (dp[i][j] > 0) {
int hsh = 0;
fore(c, s[i][j]) hsh = (1LL * hsh * B % MOD + c) % MOD;
foru(c, 1, k) if (hsh == one[i+1][c] || hsh == two[i+1][c])
add(dp[i+1][c], dp[i][j]);
}
}
int ans = 0;
foru(i, 1, k) add(ans, dp[n][i]);
cout << ans;
}
Compilation message
trener.cpp: In function 'void setIO()':
trener.cpp:22:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
22 | freopen(file".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
trener.cpp:23:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
23 | freopen(file".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2908 KB |
Output is correct |
2 |
Correct |
1 ms |
2908 KB |
Output is correct |
3 |
Correct |
1 ms |
2908 KB |
Output is correct |
4 |
Correct |
1 ms |
2864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
3672 KB |
Output is correct |
2 |
Correct |
5 ms |
3676 KB |
Output is correct |
3 |
Correct |
5 ms |
3676 KB |
Output is correct |
4 |
Correct |
5 ms |
3676 KB |
Output is correct |
5 |
Correct |
5 ms |
3676 KB |
Output is correct |
6 |
Correct |
5 ms |
3676 KB |
Output is correct |
7 |
Correct |
5 ms |
3672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2908 KB |
Output is correct |
2 |
Correct |
1 ms |
2908 KB |
Output is correct |
3 |
Correct |
1 ms |
2908 KB |
Output is correct |
4 |
Correct |
1 ms |
2864 KB |
Output is correct |
5 |
Correct |
6 ms |
3672 KB |
Output is correct |
6 |
Correct |
5 ms |
3676 KB |
Output is correct |
7 |
Correct |
5 ms |
3676 KB |
Output is correct |
8 |
Correct |
5 ms |
3676 KB |
Output is correct |
9 |
Correct |
5 ms |
3676 KB |
Output is correct |
10 |
Correct |
5 ms |
3676 KB |
Output is correct |
11 |
Correct |
5 ms |
3672 KB |
Output is correct |
12 |
Correct |
154 ms |
8240 KB |
Output is correct |
13 |
Correct |
155 ms |
8568 KB |
Output is correct |
14 |
Correct |
148 ms |
8276 KB |
Output is correct |
15 |
Correct |
169 ms |
8276 KB |
Output is correct |
16 |
Correct |
152 ms |
8152 KB |
Output is correct |
17 |
Correct |
159 ms |
8364 KB |
Output is correct |
18 |
Correct |
159 ms |
8280 KB |
Output is correct |
19 |
Correct |
158 ms |
8160 KB |
Output is correct |
20 |
Correct |
158 ms |
8232 KB |
Output is correct |
21 |
Correct |
160 ms |
8280 KB |
Output is correct |
22 |
Correct |
153 ms |
8260 KB |
Output is correct |