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;
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 (stderr)
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |