#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define debug(x) cerr << '[' << (#x) << "] = " << x << '\n';
template<class T> using ordered_set = tree<T, null_type , less<T> , rb_tree_tag , tree_order_statistics_node_update> ;
const int Mod = 1e9 + 7;
void PlayGround() {
int n, k; cin >> n >> k;
vector<vector<string>>buck(n, vector<string>(k));
for(int i=0; i<n; ++i) {
for(auto& it : buck[i])
cin >> it;
}
auto substring = [=] (string& s, string& t) {
if((s[0]==t[0] && s.substr(0, t.size())==t) || (s.back()==t.back() && s.substr(1, t.size())==t))
return true;
return false;
};
vector<int>dp(n*k);
int ans = 0;
for(int i=0; i<k; ++i) dp[i] = 1;
for(int i=0; i<n-1; ++i) {
for(int j=0; j<k; ++j) {
if(j && buck[i][j]==buck[i][j-1]) {
dp[i*k+j] = dp[i*k+j-1];
continue;
}
for(int l=0; l<k; ++l) {
if(substring(buck[i+1][l], buck[i][j])) {
dp[(i+1)*k + l] = (dp[(i+1)*k+l] + dp[i*k+j]) % Mod;
}
}
}
}
for(int i=(n-1)*k; i<n*k; ++i) ans = (ans + dp[i]) % Mod;
cout << ans << '\n';
#ifndef ONLINE_JUDGE
cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// #endif
PlayGround();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
588 KB |
Output is correct |
2 |
Correct |
5 ms |
672 KB |
Output is correct |
3 |
Incorrect |
6 ms |
668 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |