# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
530941 | Servus2022 | Trener (COCI20_trener) | C++14 | 298 ms | 26104 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;
constexpr int MOD = 1e9 + 7;
int N, K;
map <string, int> dp;
map <string, int> lg;
void Read () {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> N >> K;
}
void Solve () {
for (int i = 1; i <= N; ++ i ) {
for (int j = 1; j <= K; ++ j ) {
string S;
cin >> S;
if (i == 1) {
dp[S] ++;
lg[S] = 1;
continue;
}
string primul, aldoilea;
for (int k = 0; k < S.size()-1; ++ k ) {
primul.push_back(S[k]);
aldoilea.push_back(S[k+1]);
}
if (primul == aldoilea) {
if (lg[primul] == i-1) {
lg[S] = i;
dp[S] = (dp[S] + dp[primul]) % MOD;
}
continue;
}
if (lg[primul] == i-1) {
lg[S] = i;
dp[S] = (dp[S] + dp[primul]) % MOD;
}
if (lg[aldoilea] == i-1) {
lg[S] = i;
dp[S] = (dp[S] + dp[aldoilea]) % MOD;
}
}
}
int ans = 0;
for (auto it : dp) {
if (lg[it.first] == N) ans = (ans + it.second) % MOD;
}
cout << ans << '\n';
}
int main () {
Read();
Solve();
return 0;
}
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... |