# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
223222 | cheeheng | Trener (COCI20_trener) | C++14 | 152 ms | 14200 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 long long MOD = 1e9+7;
long long dp[55][1505];
char str[55];
string A[55][1505];
map<string, long long> m[55];
int main(){
int N, K;
scanf("%d%d", &N, &K);
for(int i = 1; i <= N; i ++){
for(int j = 0; j < K; j ++){
memset(str, 0, sizeof(str));
scanf(" %s", str);
A[i][j] = string(str);
if(i == 1){
dp[i][j] = 1;
}else{
string str1 = A[i][j].substr(1);
string str2 = A[i][j].substr(0, i-1);
//printf("%s %s\n", str1.c_str(), str2.c_str());
dp[i][j] = 0;
if(m[i-1].find(str1) != m[i-1].end()){
dp[i][j] += m[i-1][str1];
}
if(m[i-1].find(str2) != m[i-1].end() && str1 != str2){
dp[i][j] += m[i-1][str2];
}
}
dp[i][j] %= MOD;
if(m[i].find(A[i][j]) == m[i].end()){
m[i][A[i][j]] = dp[i][j];
}else{
m[i][A[i][j]] += dp[i][j];
}
}
}
long long ans = 0;
for(int i = 0; i < K; i ++){
ans += dp[N][i];
}
ans %= MOD;
printf("%lld", ans);
return 0;
}
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... |