#include <iostream>
#include <algorithm>
using namespace std;
int main(){
int n, k;
int64_t mod = 1000000007, *scores, *newscores;
string *surnames, *newsurnames;
cin >> n >> k;
surnames = new string[k];
newsurnames = new string[k];
scores = new int64_t[k];
newscores = new int64_t[k];
for (int i = 0; i < k; i++){
cin >> surnames[i];
scores[i] = 1;
}
for (int newlen = 2; newlen <= n; newlen++){
for (int i = 0; i < k; i++){
cin >> newsurnames[i];
newscores[i] = 0;
for (int j = 0; j < k; j++){
if (newsurnames[i][0] + surnames[j] == newsurnames[i] || surnames[j] + newsurnames[i][newlen - 1] == newsurnames[i]){
newscores[i] = (newscores[i] + scores[j]) % mod;
}
}
}
for (int i = 0; i < k; i++){
surnames[i] = newsurnames[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 |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
440 KB |
Output is correct |
2 |
Correct |
38 ms |
344 KB |
Output is correct |
3 |
Correct |
45 ms |
344 KB |
Output is correct |
4 |
Correct |
18 ms |
344 KB |
Output is correct |
5 |
Correct |
38 ms |
700 KB |
Output is correct |
6 |
Correct |
42 ms |
592 KB |
Output is correct |
7 |
Correct |
21 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
600 KB |
Output is correct |
5 |
Correct |
37 ms |
440 KB |
Output is correct |
6 |
Correct |
38 ms |
344 KB |
Output is correct |
7 |
Correct |
45 ms |
344 KB |
Output is correct |
8 |
Correct |
18 ms |
344 KB |
Output is correct |
9 |
Correct |
38 ms |
700 KB |
Output is correct |
10 |
Correct |
42 ms |
592 KB |
Output is correct |
11 |
Correct |
21 ms |
344 KB |
Output is correct |
12 |
Execution timed out |
2040 ms |
780 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |