Submission #824858

# Submission time Handle Problem Language Result Execution time Memory
824858 2023-08-14T11:19:19 Z faruk Lottery (CEOI18_lot) C++17
100 / 100
1450 ms 8372 KB
#include <bits/stdc++.h>
#define mp make_pair
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
 
int n, l;
void shift_forward(vector<int> &arr) {
    for (int i = 2 * n - 1; i > 0; i--)
        arr[i] = arr[i - 1];
    arr[0] = 0;
}
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
 
    cin >> n >> l;
    vector<int> arr(n);
    for (int i = 0; i < n; i++)
        cin >> arr[i];
    
    int q;
    cin >> q;
    vector<int> vals(q);
    for (int Q = 0; Q < q; Q++) {
        cin >> vals[Q];
    }
 
    vector<vector<int> > mat(q, vector<int>(n, 0));
 
    vector<int> csum(n + 1, 0);
    vector<int> diff(2 * n, 0);
    for (int i = 0; i < l; i++) {
        for (int j = 0; j < n; j++) {
            if (arr[i] != arr[j])
                diff[j - i + n]++;
        }
    }
    for (int j = 0; j <= n - l; j++)
        csum[diff[j + n]]++;
    csum[0]--;
    for (int j = 1; j < n; j++)
        csum[j] += csum[j - 1];
        
    for (int j = 0; j < q; j++)
        mat[j][0] = csum[vals[j]];
 
    for (int i = 1; i <= n - l; i++) {
        for (int j = 0; j < n; j++)
            if (arr[i - 1] != arr[j])
                diff[j + n]--;
        shift_forward(diff);
        for (int j = 0; j < n; j++)
            if (arr[i + l - 1] != arr[j])
                diff[j + 1 - l + n]++;
            
 
        fill(csum.begin(), csum.end(), 0);
        for (int j = 0; j <= n - l; j++)
            csum[diff[j + n]]++;
        csum[0]--;
        for (int j = 1; j < n; j++)
            csum[j] += csum[j - 1];
        
        for (int j = 0; j < q; j++)
            mat[j][i] = csum[vals[j]];
    }
 
    for (int Q = 0; Q < q; Q++) {
        cout << mat[Q][0];
        for (int i = 1; i <= n - l; i++)
            cout <<" " << mat[Q][i];
        cout << "\n";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 28 ms 380 KB Output is correct
14 Correct 19 ms 528 KB Output is correct
15 Correct 19 ms 456 KB Output is correct
16 Correct 27 ms 516 KB Output is correct
17 Correct 25 ms 524 KB Output is correct
18 Correct 24 ms 520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1424 ms 512 KB Output is correct
2 Correct 1392 ms 520 KB Output is correct
3 Correct 788 ms 520 KB Output is correct
4 Correct 689 ms 600 KB Output is correct
5 Correct 302 ms 596 KB Output is correct
6 Correct 641 ms 600 KB Output is correct
7 Correct 313 ms 600 KB Output is correct
8 Correct 456 ms 600 KB Output is correct
9 Correct 663 ms 596 KB Output is correct
10 Correct 670 ms 608 KB Output is correct
11 Correct 40 ms 460 KB Output is correct
12 Correct 390 ms 560 KB Output is correct
13 Correct 376 ms 596 KB Output is correct
14 Correct 358 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1424 ms 512 KB Output is correct
2 Correct 1392 ms 520 KB Output is correct
3 Correct 788 ms 520 KB Output is correct
4 Correct 689 ms 600 KB Output is correct
5 Correct 302 ms 596 KB Output is correct
6 Correct 641 ms 600 KB Output is correct
7 Correct 313 ms 600 KB Output is correct
8 Correct 456 ms 600 KB Output is correct
9 Correct 663 ms 596 KB Output is correct
10 Correct 670 ms 608 KB Output is correct
11 Correct 40 ms 460 KB Output is correct
12 Correct 390 ms 560 KB Output is correct
13 Correct 376 ms 596 KB Output is correct
14 Correct 358 ms 596 KB Output is correct
15 Correct 699 ms 520 KB Output is correct
16 Correct 619 ms 596 KB Output is correct
17 Correct 682 ms 596 KB Output is correct
18 Correct 696 ms 596 KB Output is correct
19 Correct 714 ms 596 KB Output is correct
20 Correct 688 ms 596 KB Output is correct
21 Correct 701 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 28 ms 380 KB Output is correct
14 Correct 19 ms 528 KB Output is correct
15 Correct 19 ms 456 KB Output is correct
16 Correct 27 ms 516 KB Output is correct
17 Correct 25 ms 524 KB Output is correct
18 Correct 24 ms 520 KB Output is correct
19 Correct 1424 ms 512 KB Output is correct
20 Correct 1392 ms 520 KB Output is correct
21 Correct 788 ms 520 KB Output is correct
22 Correct 689 ms 600 KB Output is correct
23 Correct 302 ms 596 KB Output is correct
24 Correct 641 ms 600 KB Output is correct
25 Correct 313 ms 600 KB Output is correct
26 Correct 456 ms 600 KB Output is correct
27 Correct 663 ms 596 KB Output is correct
28 Correct 670 ms 608 KB Output is correct
29 Correct 40 ms 460 KB Output is correct
30 Correct 390 ms 560 KB Output is correct
31 Correct 376 ms 596 KB Output is correct
32 Correct 358 ms 596 KB Output is correct
33 Correct 699 ms 520 KB Output is correct
34 Correct 619 ms 596 KB Output is correct
35 Correct 682 ms 596 KB Output is correct
36 Correct 696 ms 596 KB Output is correct
37 Correct 714 ms 596 KB Output is correct
38 Correct 688 ms 596 KB Output is correct
39 Correct 701 ms 600 KB Output is correct
40 Correct 1417 ms 2036 KB Output is correct
41 Correct 117 ms 1344 KB Output is correct
42 Correct 610 ms 2048 KB Output is correct
43 Correct 700 ms 1764 KB Output is correct
44 Correct 683 ms 1856 KB Output is correct
45 Correct 1450 ms 8240 KB Output is correct
46 Correct 125 ms 4684 KB Output is correct
47 Correct 730 ms 8372 KB Output is correct
48 Correct 739 ms 6524 KB Output is correct
49 Correct 740 ms 7164 KB Output is correct