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>
#define sz(x) ((int)x.size())
#define ft first
#define sd second
using namespace std;
typedef long long ll;
const int N = 5010;
const int oo = 2e9;
const ll OO = 1e18;
const int md = int(1e9) + 7;
short tp[N], pre[N], net[N], vl[2][N], ad[2][N][N], n, m, k;
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef _LOCAL
freopen("in.txt","r",stdin);
#endif // _LOCAL
cin >> n >> m >> k;
k = min(m, k);
for (int i = 0; i < n; i++) {
cin >> tp[i];
pre[i] = (i - 1 + n) % n;
net[i] = (i + 1) % n;
}
if (m == 1){
for (int i = 0; i < n; i++)
cout << (tp[i] ^ 1) << " ";
return 0;
}
for (int i = 0; i < n; i++){
int rt = m - 2;
int lf = max(0, m - 1 - k);
ad[0][pre[i]][rt]++;
if (lf > 0)
ad[0][pre[i]][lf - 1]--;
}
for (int j = m - 2; j >= 0; j--){
for (int i = 0; i < n; i++){
vl[0][i] += ad[0][i][j];
vl[1][i] += ad[1][i][j];
int typ = 0;
if (tp[net[i]] == tp[i]){
if (vl[1][i] > 0)
typ = 1;
} else {
if (vl[0][i] > 0)
typ = 1;
}
if (j == 0)
cout << (tp[i] ^ 1 ^ typ) << " ";
else {
int rt = j - 1;
int lf = max(0, j - k);
ad[typ][pre[i]][rt]++;
if (lf > 0)
ad[typ][pre[i]][lf - 1]--;
}
}
}
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... |
# | 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... |