#include <iostream>
#include <algorithm>
using namespace std;
int main(){
int n, k;
bool isvalid;
int64_t mod = 1000000007, *scores, *newscores, *codes, *newcodes, pow26 = 1;
string surname, newsurname;
cin >> n >> k;
scores = new int64_t[k];
newscores = new int64_t[k];
codes = new int64_t[k];
newcodes = new int64_t[k];
for (int i = 0; i < k; i++){
cin >> surname;
codes[i] = surname[0] - 'a';
scores[i] = 1;
}
for (int newlen = 2; newlen <= n; newlen++){
pow26 = (pow26 * 26) % mod;
for (int i = 0; i < k; i++){
cin >> newsurname;
newscores[i] = 0;
newcodes[i] = 0;
for (int letter = 0; letter < newlen; letter++){
newcodes[i] = (newcodes[i] * 26 + (newsurname[letter] - 'a')) % mod;
}
for (int j = 0; j < k; j++){
isvalid = false;
for (int newletter = 0; newletter < 26; newletter++){
if ((codes[j] * 26 + newletter) % mod == newcodes[i]){
isvalid = true;
break;
}
if ((codes[j] + pow26 * newletter) % mod == newcodes[i]){
isvalid = true;
break;
}
}
if (isvalid) newscores[i] = (newscores[i] + scores[j]) % mod;
}
}
for (int i = 0; i < k; i++){
codes[i] = newcodes[i];
scores[i] = newscores[i];
}
}
int64_t total = 0;
for (int i = 0; i < k; i++){
total = (total + scores[i]) % mod;
}
cout << total;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
344 KB |
Output is correct |
2 |
Correct |
33 ms |
348 KB |
Output is correct |
3 |
Correct |
30 ms |
344 KB |
Output is correct |
4 |
Correct |
6 ms |
344 KB |
Output is correct |
5 |
Correct |
39 ms |
416 KB |
Output is correct |
6 |
Correct |
39 ms |
408 KB |
Output is correct |
7 |
Correct |
29 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
32 ms |
344 KB |
Output is correct |
6 |
Correct |
33 ms |
348 KB |
Output is correct |
7 |
Correct |
30 ms |
344 KB |
Output is correct |
8 |
Correct |
6 ms |
344 KB |
Output is correct |
9 |
Correct |
39 ms |
416 KB |
Output is correct |
10 |
Correct |
39 ms |
408 KB |
Output is correct |
11 |
Correct |
29 ms |
344 KB |
Output is correct |
12 |
Execution timed out |
2044 ms |
344 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |