# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
845507 | vjudge1 | Trener (COCI20_trener) | C++17 | 1797 ms | 524288 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;
#define int long long
const int MOD = 1e9+7;
int32_t main(){
int n,k;
cin>>n>>k;
vector<vector<int>> dp(n,vector<int>(k,0));
vector<vector<string>> _arr(n,vector<string>(k));
for (int i = 0; i < n; i++){
for (int j = 0; j < k; j++){
cin>>_arr[i][j];
}
}
vector<vector<vector<int>>> arr(n-1,vector<vector<int>>(k));
map<string,vector<int>> mp;
for (int i = 0; i < n; i++){
for (int j = 0; j < k; j++){
mp[_arr[i][j]].push_back(j);
}
}
for (int i = 0; i < n-1; i++){
for (int j = 0; j < k; j++){
string str = _arr[i][j];
set<string> needless;
for (char chr = 'a'; chr <= 'z'; chr++){
needless.insert(str+chr);
needless.insert(chr+str);
}
for (auto it : needless){
if (mp.count(it)){
for (auto it2 : mp[it]){
arr[i][j].push_back(it2);
}
}
}
}
}
for (int node = n-1; node >= 0; node--){
for (int flag = 0; flag < k; flag++){
if (node==n-1){
dp[node][flag]=1;
continue;
}
for (int i = 0; i < arr[node][flag].size(); i++){
dp[node][flag]+=dp[node+1][arr[node][flag][i]];
dp[node][flag]%=MOD;
}
}
}
int ans = 0;
for (int i = 0; i < k; i++){
ans+=dp[0][i];
ans%=MOD;
}
cout<<ans<<endl;
}
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... |