Submission #602422

# Submission time Handle Problem Language Result Execution time Memory
602422 2022-07-23T05:38:15 Z pakhomovee Lottery (CEOI18_lot) C++17
100 / 100
808 ms 8440 KB
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;
const int maxn = 10000;
int a[maxn];
int prv[maxn];
int curr[maxn];
pair<int, int> queries[100];
int answer[101][maxn];
int rev[101];
int lb[maxn + 1];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, l;
    cin >> n >> l;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    int q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        cin >> queries[i].first;
        queries[i].second = i;
    }
    sort(queries, queries + q);
    for (int i = 0; i < n; ++i) {
        prv[i] = (a[0] != a[i]);
    }
    for (int i = 1; i < l; ++i) {
        for (int j = 1; j < n; ++j) {
            curr[j] = prv[j - 1] + (a[i] != a[j]);
        }
        memcpy(prv, curr, maxn * sizeof(int));
    }
    fill(lb, lb + maxn + 1, q);
    for (int i = 0; i <= n; ++i) {
        for (int j = 0; j < q; ++j) {
            if (queries[j].first >= i ){
                lb[i] = j;
                break;
            }
        }
    }
    for (int j = l - 1; j < n; ++j) {
        int mxQid = lb[curr[j]];
        ++answer[mxQid][l - 1];
    }
    for (int i = l; i < n; ++i) {
        curr[l - 1] = 0;
        for (int p = 0; p < l; ++p) {
            if (a[i - p] != a[l - p - 1]) ++curr[l - 1];
        }
        for (int j = l; j < n; ++j) {
            curr[j] = prv[j - 1] - (a[i - l] != a[j - l]) + (a[i] != a[j]);
        }
        memcpy(prv, curr, maxn * sizeof(int));
        for (int j = l - 1; j < n; ++j) {
            int mxQid = lb[curr[j]];
            ++answer[mxQid][i];
        }
    }
    for (int i = 0; i < q; ++i) {
        for (int j = l - 1; j < n; ++j) {
            if (i > 0) answer[i][j] += answer[i - 1][j];
        }
    }
    for (int i = 0; i < q; ++i) {
        rev[queries[i].second] = i;
    }
    for (int i = 0; i < q; ++i) {
        for (int j = l - 1; j < n; ++j) {
            cout << answer[rev[i]][j] - 1 << ' ';
        }
        cout << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 3 ms 468 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 3 ms 468 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 34 ms 464 KB Output is correct
14 Correct 22 ms 596 KB Output is correct
15 Correct 21 ms 580 KB Output is correct
16 Correct 33 ms 756 KB Output is correct
17 Correct 26 ms 708 KB Output is correct
18 Correct 25 ms 672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 729 ms 644 KB Output is correct
2 Correct 594 ms 588 KB Output is correct
3 Correct 722 ms 668 KB Output is correct
4 Correct 679 ms 760 KB Output is correct
5 Correct 291 ms 620 KB Output is correct
6 Correct 633 ms 768 KB Output is correct
7 Correct 245 ms 532 KB Output is correct
8 Correct 398 ms 664 KB Output is correct
9 Correct 703 ms 636 KB Output is correct
10 Correct 692 ms 620 KB Output is correct
11 Correct 39 ms 452 KB Output is correct
12 Correct 436 ms 608 KB Output is correct
13 Correct 370 ms 604 KB Output is correct
14 Correct 364 ms 608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 729 ms 644 KB Output is correct
2 Correct 594 ms 588 KB Output is correct
3 Correct 722 ms 668 KB Output is correct
4 Correct 679 ms 760 KB Output is correct
5 Correct 291 ms 620 KB Output is correct
6 Correct 633 ms 768 KB Output is correct
7 Correct 245 ms 532 KB Output is correct
8 Correct 398 ms 664 KB Output is correct
9 Correct 703 ms 636 KB Output is correct
10 Correct 692 ms 620 KB Output is correct
11 Correct 39 ms 452 KB Output is correct
12 Correct 436 ms 608 KB Output is correct
13 Correct 370 ms 604 KB Output is correct
14 Correct 364 ms 608 KB Output is correct
15 Correct 632 ms 564 KB Output is correct
16 Correct 665 ms 712 KB Output is correct
17 Correct 776 ms 708 KB Output is correct
18 Correct 693 ms 612 KB Output is correct
19 Correct 689 ms 632 KB Output is correct
20 Correct 706 ms 624 KB Output is correct
21 Correct 636 ms 648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 3 ms 468 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 34 ms 464 KB Output is correct
14 Correct 22 ms 596 KB Output is correct
15 Correct 21 ms 580 KB Output is correct
16 Correct 33 ms 756 KB Output is correct
17 Correct 26 ms 708 KB Output is correct
18 Correct 25 ms 672 KB Output is correct
19 Correct 729 ms 644 KB Output is correct
20 Correct 594 ms 588 KB Output is correct
21 Correct 722 ms 668 KB Output is correct
22 Correct 679 ms 760 KB Output is correct
23 Correct 291 ms 620 KB Output is correct
24 Correct 633 ms 768 KB Output is correct
25 Correct 245 ms 532 KB Output is correct
26 Correct 398 ms 664 KB Output is correct
27 Correct 703 ms 636 KB Output is correct
28 Correct 692 ms 620 KB Output is correct
29 Correct 39 ms 452 KB Output is correct
30 Correct 436 ms 608 KB Output is correct
31 Correct 370 ms 604 KB Output is correct
32 Correct 364 ms 608 KB Output is correct
33 Correct 632 ms 564 KB Output is correct
34 Correct 665 ms 712 KB Output is correct
35 Correct 776 ms 708 KB Output is correct
36 Correct 693 ms 612 KB Output is correct
37 Correct 689 ms 632 KB Output is correct
38 Correct 706 ms 624 KB Output is correct
39 Correct 636 ms 648 KB Output is correct
40 Correct 737 ms 2032 KB Output is correct
41 Correct 118 ms 716 KB Output is correct
42 Correct 808 ms 2084 KB Output is correct
43 Correct 637 ms 1720 KB Output is correct
44 Correct 643 ms 1876 KB Output is correct
45 Correct 805 ms 8132 KB Output is correct
46 Correct 130 ms 1616 KB Output is correct
47 Correct 759 ms 8440 KB Output is correct
48 Correct 799 ms 6540 KB Output is correct
49 Correct 767 ms 7252 KB Output is correct