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: tmhazem1
LANG: C++14
TASK: pprime
*/
#include <bits/stdc++.h>
using namespace std;
#define S second
#define F first
#define LL long long
const int N = 2e5 + 10;
LL LINF = 100000000000000000;
LL INF = 1000000000;
int MOD = 1e9+7;
string s[55][2000];
LL ans[55][2000];
map<string,LL>mp;
LL add(LL a,LL b){
return (a+b)%MOD;
}
string sub(string s,int l,int r){
string ret = "";
for(int i=l;i<=r;i++)
ret += s[i];
return ret;
}
bool check(string s,string r){
bool q = 0;
for(int i=0;i<2;i++)
q |= sub(r,i,i+s.size()-1)==s;
return q;
}
int main()
{
//freopen("out.txt","w",stdout);
int n,k;
scanf("%d%d",&n,&k);
for(int i=1;i<=n;i++)
for(int j=1;j<=k;j++)
cin>>s[i][j];
for(int i=1;i<=k;i++)
ans[n][i] = 1;
for(int i=1;i<=k;i++){
string r1 = sub(s[n][i],0,n-2);
string r2 = sub(s[n][i],1,n-1);
mp[r1]++;
if(r2!=r1)mp[r2]++;
}
for(int i=n-1;i>=2;i--){
for(int j=1;j<=k;j++){
string r1 = sub(s[i][j],0,i-2);
string r2 = sub(s[i][j],1,i-1);
mp[r1] = add(mp[r1],mp[s[i][j]]);
if(r2!=r1)
mp[r2] = add(mp[r2],mp[s[i][j]]);
}
}
LL ans1 = 0;
for(int i=1;i<=k;i++)
ans1 = add(ans1,mp[s[1][i]]);
printf("%lld\n",ans1);
}
Compilation message (stderr)
trener.cpp: In function 'int main()':
trener.cpp:51:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
51 | scanf("%d%d",&n,&k);
| ~~~~~^~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |