Submission #161373

# Submission time Handle Problem Language Result Execution time Memory
161373 2019-11-02T05:37:16 Z rama_pang Lottery (CEOI18_lot) C++14
0 / 100
779 ms 460 KB
#include <bits/stdc++.h>
using namespace std;

int N, L, q, A[10005];
int ans[100][10005];
pair<int, int> Q[100];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    cin >> N >> L; for (int i = 0; i < N; i++) cin >> A[i];
    cin >> q; for (int i = 0; i < q; i++) cin >> Q[i].first;
    for (int i = 0; i < q; i++) Q[i].second = i;
    sort(Q, Q + q);

    /* The segment compared is segment i...(i + L - 1) and (i + shift)...(i + L + shift - 1) */
    for (int shift = 1, similiar = 0; shift + L - 1 < N; shift++, similiar = 0) {
        for (int i = 0; i < L; i++) 
            if (A[i] == A[i + shift]) similiar++;
        
        for (int i = 0; i + shift + L - 1 < N; i++) { // then sliding window can be used
            int j = lower_bound(Q, Q + q, make_pair(L - similiar, -1)) - Q;
            ans[Q[j].second][i]++, ans[Q[j].second][i + shift]++; // Add 1 to the answer for the lowest Q possible

            if (A[i] == A[i + shift]) similiar--;
            if (A[i + L] == A[i + shift + L]) similiar++;
        }
    }
    
    /* If Q[i] <= Q[j], then all answers from Q[i] can be used in Q[j] */
    for (int i = 0; i < N; i++) 
        for (int j = 1; j < q; j++) 
            ans[Q[j].second][i] += ans[Q[j - 1].second][i];

    for (int i = 0; i < q; i++) {
        for (int j = 0; j < N - L + 1; j++) 
            cout << ans[i][j] << " ";

        cout << "\n";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 779 ms 460 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 779 ms 460 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -