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 <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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |