# JZOJ – 5778 没有硝烟的战争

Time Limit : 3000ms
Memory Limit : 512MB

## Sample Input

### Case 1

2 9 2
0 1


### Case 2

6 499 5
1 0 0 1 1 0


### Case 3

10 100 10
0 0 0 1 1 1 1 0 1 1


## Sample Output

### Case 1

0 1


### Case 2

0 1 1 1 1 0


### Case 3

1 1 1 1 1 1 1 1 1 1


## 代码

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>

using namespace std;
const int MAXN = 5000 + 10;

int x = 0;
char ch = getchar();

while(ch < '0' || ch > '9'){
ch = getchar();
}

while('0' <= ch && ch <= '9'){
x = x*10 + ch - '0';
ch = getchar();
}

return x;
}

int data[MAXN];
int f[MAXN][MAXN];
int sum[MAXN][MAXN];

int n, m, k;

int main(){

//freopen("vode.in", "r", stdin);
//freopen("vode.out", "w", stdout);

for(register int i=1; i<=n; i++){
}

for(register int j=m-1; j>=1; j--){
for(register int i=1; i<=n; i++){
int next = (i % n) + 1;

if(data[i] == data[next]){
//similar to next

if(sum[next][j+1] - sum[next][min(m, j+k)+1] > 0)
f[i][j] = 1;
else
f[i][j] = 0;
}else{
if(sum[next][j+1] - sum[next][min(m, j+k)+1] == 0)
f[i][j] = 1;
else
f[i][j] = 0;
}

sum[i][j] = sum[i][j+1] + f[i][j];
}
}

for(register int i=1; i<=n; i++){
bool flag = true;

for(register int j=1; j<=k; j++){
if(f[i][j]){
flag = false;
break;
}
}

if(flag)
data[i] = !data[i];

printf("%d ", data[i]);
}
}