# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
845398 | vjudge1 | Trener (COCI20_trener) | C++17 | 2008 ms | 5580 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 sp " "
#define endl "\n";
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define pb push_back
#define pii pair<int, int>
#define st first
#define nd second
#define N 2005
#define int long long
const int modulo = 1e9 + 7;
int dp[N], dpold[N];
int add(int a, int b){
if (a + b < modulo) return a + b;
return a + b - modulo;
}
int contains(string &a, string &b){
string tmp = b + "$" + a;
vector<int> p(tmp.size(), 0);
for (int i = 1; i < tmp.size(); i++){
int prv = i - 1;
while(prv >= 0){
if (tmp[p[prv]] == tmp[i]){
p[i] = p[prv] + 1;
break;
}
else{
prv = p[prv] - 1;
}
}
if (p[i] == b.size()) return 1;
}
return 0;
}
int32_t main()
{
fastio();
int n, k;
cin>>n>>k;
vector<string> arr[n + 5];
for (int i = 1; i <= n; i++){
for (int j = 1; j <= k; j++)
{
string tmp;
cin>>tmp;
arr[i].pb(tmp);
}
}
for (int i = 0; i <= k; i++){
dpold[i] = 1;
}
for (int i = n - 1; i >= 1; i--){
for (int j = 0; j < k; j++){
for (int l = 0; l < k; l++){
if (contains(arr[i + 1][l], arr[i][j])) dp[j] = add(dp[j], dpold[l]);
}
}
for (int j = 0; j < k; j++)
dpold[j] = dp[j], dp[j] = 0;
}
int ans = 0;
for (int i = 0; i < k; i++)
ans = add(ans, dpold[i]);
cout<<ans<<endl;
cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " seconds\n";
}
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... |