Submission #219342

#TimeUsernameProblemLanguageResultExecution timeMemory
219342VimmerTrener (COCI20_trener)C++14
55 / 110
2088 ms5792 KiB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

#define F first
#define S second
#define sz(x) ll(x.size())
#define pb push_back
#define N 75005
#define M ll(1e9 + 7)

using namespace std;
//using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef short int si;

//typedef tree<int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> oredered_set;


bool gd(string s, string p)
{
    for (int i = 0; i <= sz(p) - sz(s); i++)
    {
        int j = 0;

        while (j < sz(s) && s[j] == p[j + i]) j++;

        if (j == sz(s)) return 1;
    }

    return 0;
}

ll dp[51][1501];

int main()
{
    ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int n, k;

    cin >> n >> k;

    string s[n][k];

    for (int i = 0; i < n; i++)
        for (int j = 0; j < k; j++) cin >> s[i][j];

    for (int i = 0; i < k; i++) dp[0][i] = 1;

    for (int i = 0; i < n - 1; i++)
        for (int j = 0; j < k; j++)
            for (int u = 0; u < k; u++) if (gd(s[i][j], s[i + 1][u])) dp[i + 1][u] = (dp[i + 1][u] + dp[i][j]) % M;

    ll ans = 0;

    for (int i = 0; i < k; i++) ans = (ans + dp[n - 1][i]) % M;

    cout << ans << endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...