// "Say:He is the Most Merciful,We have believed in him and upon him we have relied" [67:29]
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
map<deque<char>, vector<int>>mp;
void add_self(int &a, int b){
a += b;
if(a >= mod){
a -= mod;
}
}
int main(){
int n, m; cin >> n >> m;
vector< vector<deque<char> > >v(n+1, vector<deque<char>>(m+1));
vector<vector<int>>dp(n+1, vector<int>(m+1));
vector< vector<bool> >flag(n+1, vector<bool>(m+1));
for(int i=1;i<=n; i++){
for(int j=1; j<=m; j++){
for(int x=1; x<=i; x++){
char val; cin >> val;
v[i][j].push_back(val);
}
if(count(v[i][j].begin(), v[i][j].end(), v[i][j][0]) == (int)v[i][j].size()){
flag[i][j] = 1;
}
mp[v[i][j]].push_back(j);
if(i == n){
dp[i][j] = 1;
}
}
}
for(int i=n; i>=2; i--){
for(int x=1; x<=m; x++){
char val = v[i][x].back();
v[i][x].pop_back();
for(int e:mp[v[i][x]]){
add_self(dp[i-1][e], dp[i][x]);
}
v[i][x].push_back(val);
if(flag[i][x]){
continue;
}
val = v[i][x].front();
v[i][x].pop_front();
for(int e:mp[v[i][x]]){
add_self(dp[i-1][e], dp[i][x]);
}
v[i][x].push_front(val);
}
}
int sum = 0;
for(int i=1; i<=m; i++){
add_self(sum, dp[1][i]);
}
cout << sum << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
11036 KB |
Output is correct |
2 |
Correct |
31 ms |
10988 KB |
Output is correct |
3 |
Correct |
29 ms |
11088 KB |
Output is correct |
4 |
Correct |
17 ms |
3964 KB |
Output is correct |
5 |
Correct |
28 ms |
8832 KB |
Output is correct |
6 |
Correct |
27 ms |
8824 KB |
Output is correct |
7 |
Correct |
18 ms |
3980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
31 ms |
11036 KB |
Output is correct |
6 |
Correct |
31 ms |
10988 KB |
Output is correct |
7 |
Correct |
29 ms |
11088 KB |
Output is correct |
8 |
Correct |
17 ms |
3964 KB |
Output is correct |
9 |
Correct |
28 ms |
8832 KB |
Output is correct |
10 |
Correct |
27 ms |
8824 KB |
Output is correct |
11 |
Correct |
18 ms |
3980 KB |
Output is correct |
12 |
Correct |
650 ms |
158788 KB |
Output is correct |
13 |
Correct |
634 ms |
159556 KB |
Output is correct |
14 |
Correct |
634 ms |
159556 KB |
Output is correct |
15 |
Correct |
647 ms |
159540 KB |
Output is correct |
16 |
Correct |
631 ms |
54348 KB |
Output is correct |
17 |
Correct |
578 ms |
120268 KB |
Output is correct |
18 |
Correct |
564 ms |
120748 KB |
Output is correct |
19 |
Correct |
582 ms |
120592 KB |
Output is correct |
20 |
Correct |
569 ms |
120904 KB |
Output is correct |
21 |
Correct |
561 ms |
120556 KB |
Output is correct |
22 |
Correct |
647 ms |
54336 KB |
Output is correct |