Submission #845447

# Submission time Handle Problem Language Result Execution time Memory
845447 2023-09-06T13:39:03 Z vjudge1 Trener (COCI20_trener) C++17
0 / 110
5 ms 1368 KB
#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,-1));
	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];
		}
	}
	function<int(int,int)> f;f=[&](int node, int flag)->int{
		if (node==n-1) return 1ll;
		if (dp[node][flag]!=-1) return dp[node][flag];
		dp[node][flag]=0;
		for (int i = 0; i < k; i++){
			bool boolean=false;
			for (int j = 0; j+node<n; j++){
				if (arr[node+1][i].substr(j,node+1)==arr[node][flag]){
					boolean=true;
					break;
				}
			}
			if (boolean){
				dp[node][flag]+=f(node+1,i);
				dp[node][flag]%=MOD;
			}
		}
		return dp[node][flag];
	};
	int ans = 0;
	for (int i = 0; i < k; i++){
		ans+=f(0,i);
		ans%=MOD;
	}
	cout<<ans<<endl;
}
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 1368 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -