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;
#define sz(x) ((int)size(x))
#define all(x) begin(x), end(x)
#define trace(x) cout << #x << ": " << (x) << endl;
typedef long long ll;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r) { return (int) ((ll) rnd() % (r - l + 1)) + l; }
const int N = 10000, N2 = 2000;
const ll infL = 3e18;
int a[N], g[N2][N2], n, l;
int count(int i, int j) {
if (i == j) return 0;
int ans = 0;
for (int id = 0; id < l; ++id) {
ans += (a[i + id] != a[j + id]);
}
return ans;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> l;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
if (n <= 2000) {
for (int i = n - l - 1; i > -1; --i) {
g[i][n - l] = g[n - l][i] = count(i, n - l);
for (int j = 1; j <= i; ++j) {
g[i - j][n - l - j] = g[n - l - j][i - j] =
g[i - j + 1][n - l - j + 1] + (a[i - j] != a[n - l - j]) - (a[i - j + l] != a[n - j]);
}
}
int q;
cin >> q;
while (q--) {
int k;
cin >> k;
for (int i = 0; i <= n - l; ++i) {
int ans = 0;
for (int j = 0; j <= n - l; ++j) {
if (i != j && g[i][j] <= k)
++ans;
}
cout << ans << " ";
}
cout << '\n';
}
} else {
assert(false);
}
return 0;
}
# | 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... |