#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int n,k;
cin >> n >> k;
string input;
string arr[n+5][k+5];
for(int i=0;i<n+5;i++){
for(int j=0;j<k+5;j++){
arr[i][j] = "1";
}
}
for(int i=0;i<n;i++){
for(int j=0;j<k;j++){
cin >> input;
arr[i][j] = input;
}
}
int has[n+5][k+5];
memset(has,0,sizeof(has));
for(int i=0;i<k;i++){
has[0][i] = 1;
}
for(int i=0;i<n-1;i++){
map<string,set<int> > map1;
for(int j=0;j<k;j++){
if(arr[i+1][j]=="1"){
continue;
}
string a = arr[i+1][j].substr(0,i+1);
string b = arr[i+1][j].substr(1,i+1);
if(map1.count(a)==0){
map1.insert({a,{}});
}
if(map1.count(b)==0){
map1.insert({b,{}});
}
map1[a].insert(j);
map1[b].insert(j);
}
for(int j=0;j<k;j++){
if(arr[i][j]=="1"){
continue;
}
if(map1.count(arr[i][j])==0){
continue;
}
for(auto l:map1[arr[i][j]]){
has[i+1][l] += has[i][j];
has[i+1][l] %= mod;
}
}
}
int ans = 0;
for(int i=0;i<k;i++){
ans += has[n-1][i];
ans %= mod;
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
896 KB |
Output is correct |
2 |
Correct |
9 ms |
896 KB |
Output is correct |
3 |
Correct |
9 ms |
896 KB |
Output is correct |
4 |
Correct |
7 ms |
896 KB |
Output is correct |
5 |
Correct |
10 ms |
896 KB |
Output is correct |
6 |
Correct |
10 ms |
896 KB |
Output is correct |
7 |
Correct |
7 ms |
896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
9 ms |
896 KB |
Output is correct |
6 |
Correct |
9 ms |
896 KB |
Output is correct |
7 |
Correct |
9 ms |
896 KB |
Output is correct |
8 |
Correct |
7 ms |
896 KB |
Output is correct |
9 |
Correct |
10 ms |
896 KB |
Output is correct |
10 |
Correct |
10 ms |
896 KB |
Output is correct |
11 |
Correct |
7 ms |
896 KB |
Output is correct |
12 |
Correct |
176 ms |
8956 KB |
Output is correct |
13 |
Correct |
178 ms |
9208 KB |
Output is correct |
14 |
Correct |
181 ms |
8952 KB |
Output is correct |
15 |
Correct |
174 ms |
8952 KB |
Output is correct |
16 |
Correct |
987 ms |
8440 KB |
Output is correct |
17 |
Correct |
219 ms |
8800 KB |
Output is correct |
18 |
Correct |
214 ms |
8824 KB |
Output is correct |
19 |
Correct |
213 ms |
8824 KB |
Output is correct |
20 |
Correct |
217 ms |
9080 KB |
Output is correct |
21 |
Correct |
216 ms |
8824 KB |
Output is correct |
22 |
Correct |
980 ms |
8440 KB |
Output is correct |