#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 fen[N][N], net[N], tp[N], n, m, k, pre[N][N], mem[N][N];
void upd(short id, short ps){
for (; ps < m; ps = (ps | (ps + 1)))
fen[id][ps]++;
}
short sum(short id, short ps){
short res = 0;
for (; ps >= 0; ps = (ps & (ps + 1)) - 1)
res += fen[id][ps];
return res;
}
short gett(short id, short vl){
if (pre[id][vl] == vl)
return vl;
else return (pre[id][vl] = gett(id, pre[id][vl]));
}
short get(short ps, short vl){
if (mem[ps][vl] > 0) return mem[ps][vl] - 1;
if (vl == m - 1) {
mem[ps][vl] = 1;
return 0;
}
short res = 0;
short rt = min(vl + k, m - 1);
while (1){
short nw = gett(net[ps], pre[net[ps]][rt]);
if (nw <= vl) break;
mem[net[ps]][nw] = get(net[ps], nw) + 1;
if (mem[net[ps]][nw] == 2)
upd(net[ps], nw);
pre[net[ps]][nw] = gett(net[ps], pre[net[ps]][nw - 1]);
}
if (tp[net[ps]] == tp[ps]){
if (sum(net[ps], rt) - sum(net[ps], vl) > 0)
res = 1;
} else {
if (sum(net[ps], rt) - sum(net[ps], vl) < rt - vl)
res = 1;
}
mem[ps][vl] = res + 1;
return res;
}
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 (short i = 0; i < n; i++) {
cin >> tp[i];
net[i] = (i + 1) % n;
for (short j = 0; j <= m; j++)
pre[i][j] = j;
}
for (short i = 0; i < n; i++){
short ans = 0;
ans = get(i, 0);
cout << (tp[i] ^ ans ^ 1) << " ";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
1280 KB |
Output is correct |
3 |
Correct |
5 ms |
896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
2944 KB |
Output is correct |
2 |
Correct |
7 ms |
1792 KB |
Output is correct |
3 |
Correct |
12 ms |
2976 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
3456 KB |
Output is correct |
2 |
Correct |
11 ms |
3200 KB |
Output is correct |
3 |
Correct |
12 ms |
3584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
4864 KB |
Output is correct |
2 |
Correct |
21 ms |
5760 KB |
Output is correct |
3 |
Correct |
19 ms |
5504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
7168 KB |
Output is correct |
2 |
Correct |
27 ms |
6784 KB |
Output is correct |
3 |
Correct |
21 ms |
6420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
6272 KB |
Output is correct |
2 |
Correct |
28 ms |
6528 KB |
Output is correct |
3 |
Correct |
5 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
489 ms |
38400 KB |
Output is correct |
2 |
Correct |
592 ms |
40824 KB |
Output is correct |
3 |
Execution timed out |
3090 ms |
121652 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1320 ms |
69952 KB |
Output is correct |
2 |
Execution timed out |
3105 ms |
126072 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3103 ms |
122616 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3100 ms |
124644 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |