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>
using namespace std;
int N, L, q, Q[100], A[10005];
int ans[100][10005];
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];
/* The segment compared is segment i...(i + L - 1) and (i + shift)...(i + L + shift - 1) */
for (int shift = 1; shift + L - 1 < N; shift++) {
int 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
for (int j = 0; j < q; j++)
if (Q[j] >= L - similiar) ans[j][i]++, ans[j][i + shift]++;
if (A[i] == A[i + shift]) similiar--;
if (A[i + L] == A[i + shift + L]) similiar++;
}
}
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |