This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
ID: antwand1
TASK: pprime
LANG: C++
*/
#include <bits/stdc++.h>
#define ll long long
#define int long long
#define du long double
#define F first
#define S second
#define FOR(a,b) for(int a=1;a<=b;a++)
#define FORl(a,b) for(a=1;a<=b;a++)
#define FOR0(a,b) for(int a=1;a<b;a++)
#define FORl0(a,b) for(a=0;a<b;a++)
#define ii pair<int,int>
using namespace std;
const int MOD=1e9+7;
const int N=55;
const int M=1511;
string a[N][M];
int dp[N][M];
int n,m;
bool ok(string a,string b)
{
string ret;
for(int i=0;i<b.size()-1;i++)ret+=b[i];
if(ret==a)return 1;
ret="";
for(int i=1;i<b.size();i++)ret+=b[i];
return ret==a;
}
int bc(int i,int j)
{
int&ret=dp[i][j];
if(ret!=-1)return ret;
if(i==n+1){
// cout<<i<<" "<<j<<endl;
return ret=1;
}
ret=0;
for(int x=1;x<=m;x++){
if(i==1)ret+=bc(i+1,x);
else{
if(ok(a[i-1][j],a[i][x]))ret+=bc(i+1,x)%MOD;
}
}
return ret;
}
main()
{
memset(dp,-1,sizeof(dp));
cin>>n>>m;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>a[i][j];
}
}
cout<<bc(1,1);
}
Compilation message (stderr)
trener.cpp: In function 'bool ok(std::string, std::string)':
trener.cpp:27:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
27 | for(int i=0;i<b.size()-1;i++)ret+=b[i];
| ~^~~~~~~~~~~
trener.cpp:30:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | for(int i=1;i<b.size();i++)ret+=b[i];
| ~^~~~~~~~~
trener.cpp: At global scope:
trener.cpp:50:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
50 | main()
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |