This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// "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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |