Submission #219355

# Submission time Handle Problem Language Result Execution time Memory
219355 2020-04-05T07:34:15 Z VEGAnn Trener (COCI20_trener) C++14
110 / 110
111 ms 8352 KB
#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
1 Correct 6 ms 3200 KB Output is correct
2 Correct 6 ms 3200 KB Output is correct
3 Correct 6 ms 3200 KB Output is correct
4 Correct 6 ms 3200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 3584 KB Output is correct
2 Correct 10 ms 3584 KB Output is correct
3 Correct 10 ms 3584 KB Output is correct
4 Correct 8 ms 3584 KB Output is correct
5 Correct 11 ms 3584 KB Output is correct
6 Correct 11 ms 3584 KB Output is correct
7 Correct 8 ms 3584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 3200 KB Output is correct
2 Correct 6 ms 3200 KB Output is correct
3 Correct 6 ms 3200 KB Output is correct
4 Correct 6 ms 3200 KB Output is correct
5 Correct 10 ms 3584 KB Output is correct
6 Correct 10 ms 3584 KB Output is correct
7 Correct 10 ms 3584 KB Output is correct
8 Correct 8 ms 3584 KB Output is correct
9 Correct 11 ms 3584 KB Output is correct
10 Correct 11 ms 3584 KB Output is correct
11 Correct 8 ms 3584 KB Output is correct
12 Correct 90 ms 6264 KB Output is correct
13 Correct 89 ms 6264 KB Output is correct
14 Correct 89 ms 6264 KB Output is correct
15 Correct 89 ms 6264 KB Output is correct
16 Correct 56 ms 6264 KB Output is correct
17 Correct 95 ms 6264 KB Output is correct
18 Correct 98 ms 8184 KB Output is correct
19 Correct 99 ms 8184 KB Output is correct
20 Correct 103 ms 8152 KB Output is correct
21 Correct 111 ms 8352 KB Output is correct
22 Correct 41 ms 8188 KB Output is correct