Submission #219362

#TimeUsernameProblemLanguageResultExecution timeMemory
219362VimmerTrener (COCI20_trener)C++14
55 / 110
2094 ms15072 KiB
#include <bits/stdc++.h> //#pragma GCC optimize("unroll-loops") //#pragma GCC optimize("-O3") //#pragma GCC optimize("Ofast") //#pragma GCC optimize("fast-math") //#pragma GCC optimize("no-stack-protector") #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; typedef long double ld; typedef long long ll; typedef short int si; vector <ll> dp, dpl; 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][3]; dp.resize(k); dpl.resize(k); for (register int i = 0; i < n; i++) for (register int j = 0; j < k; j++) {cin >> s[i][j][0]; if (i != 0) {s[i][j][1] = s[i][j][0].substr(0, i); s[i][j][2] = s[i][j][0].substr(1);} } for (register int i = 0; i < k; i++) dpl[i] = 1; for (register int i = 0; i < n - 1; i++) { for (register int j = 0; j < k; j++) { if (dpl[j] == 0) continue; for (register int u = 0; u < k; u++) if (s[i][j][0] == s[i + 1][u][1] || s[i][j][0] == s[i + 1][u][2]) dp[u] = (dp[u] + dpl[j]) % M; } dpl = dp; dp.clear(); dp.resize(k, 0ll); } ll ans = 0; for (register int i = 0; i < k; i++) ans = (ans + dpl[i]) % M; cout << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...