#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 = int(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(int id, int ps){
for (; ps < m; ps = (ps | (ps + 1)))
fen[id][ps]++;
}
int sum(int id, int ps){
int res = 0;
for (; ps >= 0; ps = (ps & (ps + 1)) - 1)
res += fen[id][ps];
return res;
}
short get(short id, short vl){
if (pre[id][vl] == vl)
return vl;
else return (pre[id][vl] = get(id, pre[id][vl]));
}
int get(int ps, int vl){
if (mem[ps][vl] > 0) return mem[ps][vl] - 1;
if (vl == m - 1) {
mem[ps][vl] = 1;
return 0;
}
int res = 0;
int rt = min(vl + k, m - 1);
while (1){
int nw = get(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] = get(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 (int i = 0; i < n; i++) {
cin >> tp[i];
net[i] = (i + 1) % n;
for (int j = 0; j <= m; j++)
pre[i][j] = j;
}
for (int i = 0; i < n; i++){
int ans = 0;
ans = get(i, 0);
cout << (tp[i] ^ ans ^ 1) << " ";
}
return 0;
}
Compilation message
vode.cpp: In function 'int get(int, int)':
vode.cpp:48:43: warning: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second:
mem[net[ps]][nw] = get(net[ps], nw) + 1;
^
vode.cpp:31:5: note: candidate 1: int get(int, int)
int get(int ps, int vl){
^~~
vode.cpp:25:7: note: candidate 2: short int get(short int, short int)
short get(short id, short vl){
^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
1280 KB |
Output is correct |
3 |
Correct |
5 ms |
1024 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
2944 KB |
Output is correct |
2 |
Correct |
8 ms |
1664 KB |
Output is correct |
3 |
Correct |
12 ms |
2944 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
3456 KB |
Output is correct |
2 |
Correct |
10 ms |
3200 KB |
Output is correct |
3 |
Correct |
12 ms |
3584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
4864 KB |
Output is correct |
2 |
Correct |
20 ms |
5760 KB |
Output is correct |
3 |
Correct |
20 ms |
5504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
7160 KB |
Output is correct |
2 |
Correct |
25 ms |
6776 KB |
Output is correct |
3 |
Correct |
19 ms |
6400 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
6272 KB |
Output is correct |
2 |
Correct |
27 ms |
6528 KB |
Output is correct |
3 |
Correct |
5 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
460 ms |
38264 KB |
Output is correct |
2 |
Correct |
571 ms |
40572 KB |
Output is correct |
3 |
Execution timed out |
3102 ms |
126028 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1234 ms |
69752 KB |
Output is correct |
2 |
Execution timed out |
3106 ms |
127480 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3099 ms |
124336 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3098 ms |
125424 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |