#include <iostream>
#include <algorithm>
#include <string>
#include <map>
using namespace std;
const long long mod = 1000000007;
map<string, long long> cnt, dptable;
long long dp(string name) {
if (cnt[name] == 0) return 0;
if (name.size() == 1) return 1;
if (dptable.find(name) != dptable.end()) return dptable[name];
long long ans = 0;
string subs[2];
for (int i = 0; i < 2; ++i) subs[i] = name.substr(i, name.size() - 1);
for (int i = 0; i <= (subs[0] != subs[1]); ++i) {
ans += dp(subs[i]) * cnt[subs[i]];
ans %= mod;
}
return dptable[name] = ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int N, K;
cin >> N >> K;
string names[N][K];
for (int i = 0; i < N; ++i) {
for (int j = 0; j < K; ++j) {
cin >> names[i][j];
++cnt[names[i][j]];
}
}
long long ans = 0;
for (int i = 0; i < K; ++i) ans = (ans + dp(names[N - 1][i])) % mod;
printf("%lld", ans);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
1408 KB |
Output is correct |
2 |
Correct |
10 ms |
1408 KB |
Output is correct |
3 |
Correct |
11 ms |
1408 KB |
Output is correct |
4 |
Correct |
6 ms |
768 KB |
Output is correct |
5 |
Correct |
14 ms |
1280 KB |
Output is correct |
6 |
Correct |
10 ms |
1280 KB |
Output is correct |
7 |
Correct |
6 ms |
640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
10 ms |
1408 KB |
Output is correct |
6 |
Correct |
10 ms |
1408 KB |
Output is correct |
7 |
Correct |
11 ms |
1408 KB |
Output is correct |
8 |
Correct |
6 ms |
768 KB |
Output is correct |
9 |
Correct |
14 ms |
1280 KB |
Output is correct |
10 |
Correct |
10 ms |
1280 KB |
Output is correct |
11 |
Correct |
6 ms |
640 KB |
Output is correct |
12 |
Correct |
125 ms |
16120 KB |
Output is correct |
13 |
Correct |
127 ms |
16120 KB |
Output is correct |
14 |
Correct |
135 ms |
16504 KB |
Output is correct |
15 |
Correct |
127 ms |
16248 KB |
Output is correct |
16 |
Correct |
23 ms |
5376 KB |
Output is correct |
17 |
Correct |
119 ms |
13944 KB |
Output is correct |
18 |
Correct |
117 ms |
13944 KB |
Output is correct |
19 |
Correct |
128 ms |
14204 KB |
Output is correct |
20 |
Correct |
122 ms |
13944 KB |
Output is correct |
21 |
Correct |
126 ms |
14072 KB |
Output is correct |
22 |
Correct |
22 ms |
5376 KB |
Output is correct |