# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
223217 | dantoh000 | Trener (COCI20_trener) | C++14 | 2086 ms | 6264 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int n,k;
int dp[2][1505];
string a[55][1505];
bool can(string a, string b){
return b.substr(1) == a || b.substr(0,b.size()-1) == a;
}
int main(){
scanf("%d%d",&n,&k);
for (int i = 1; i <= n; i++){
for (int j = 1; j <= k; j++){
cin >> a[i][j];
}
}
for (int i = 1; i <= k; i++) dp[n&1][i] = 1;
for (int i = n-1; i >= 1; i--){
for (int j = 1; j <= k; j++){
dp[i&1][j] = 0;
for (int j2 = 1; j2 <= k; j2++){
if (can(a[i][j],a[i+1][j2])){
dp[i&1][j] += dp[1-i&1][j2];
dp[i&1][j] %= mod;
}
}
}
}
int sum = 0;
for (int i = 1; i <= k; i++) {
sum += dp[1][i];
sum %= mod;
}
printf("%d",sum);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |