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 <bits/stdc++.h>
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define PB push_back
#define pii pair<int,int>
#define MP make_pair
#define ft first
#define sd second
using namespace std;
const int N = 60;
const int K = 1520;
const int oo = 2e9;
const int md = int(1e9) + 7;
string s[N][K], t, p;
int k, n, f[N][K], ad[K];
int sum(int x, int y){
x += y;
if (x >= md)
x -= md;
return x;
}
int sub(int x, int y){
x -= y;
if (x < 0)
x += md;
return x;
}
void checking(int i, int j){
int l = lower_bound(s[i - 1], s[i - 1] + k, t) - s[i - 1];
int r = upper_bound(s[i - 1], s[i - 1] + k, t) - s[i - 1];
ad[l] = sum(ad[l], f[i][j]);
ad[r] = sub(ad[r], f[i][j]);
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
// freopen("in.txt","r",stdin);
cin >> n >> k;
for (int i = 0; i < n; i++) {
for (int j = 0; j < k; j++) {
cin >> s[i][j];
if (i == n - 1)
f[i][j] = 1;
}
sort(s[i], s[i] + k);
}
for (int i = n - 1; i > 0; i--) {
fill(ad, ad + k, 0);
for (int j = 0; j < k; j++){
t = s[i][j].substr(0, i);
p = s[i][j].substr(1, i);
checking(i, j);
if (t == p) continue;
t = p;
checking(i, j);
}
int cur = 0;
for (int j = 0; j < k; j++){
cur = sum(cur, ad[j]);
f[i - 1][j] = cur;
}
}
int ans = 0;
for (int i = 0; i < k; i++)
ans = sum(ans, f[0][i]);
cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |