이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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, answer[N];
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 {
int q;
cin >> q;
assert(q == 1);
int k;
cin >> k;
for (int i = n - l - 1; i > -1; --i) {
int ct = count(i, n - l);
answer[i] += (ct <= k);
answer[n - l] += (ct <= k);
for (int j = 1; j <= i; ++j) {
ct = ct + (a[i - j] != a[n - l - j]) - (a[i - j + l] != a[n - j]);
answer[i - j] += (ct <= k);
answer[n - l - j] += (ct <= k);
}
}
for (int i = 0; i <= n - l; ++i) {
cout << answer[i] << " ";
}
cout << '\n';
}
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... |