-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgermande.cpp
70 lines (57 loc) · 1.54 KB
/
germande.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include<bits/stdc++.h>
#define MAX 1000000
#define DEBUG(x) do { std::cout << #x << ": " << x << " "; } while (0)
using namespace std;
int main()
{
int t,a[MAX],state[MAX],total,i,j,k,ans,temp,states,dist,len,x,y;
scanf("%d",&t);
while(t--){
scanf("%d%d",&states,&dist);
len=states*dist;
total=0;
memset(state,0,sizeof(state));
for(i=0;i<len;++i){
scanf("%d",&a[i]);
state[i/dist]+=a[i];
if((i+1)%dist==0){
if(state[i/dist]>= (dist+1)/2){
total+=1;
}
}
}
/*for(i=0;i<states;++i){
DEBUG(state[i]);
}
cout<<endl;*/
if(total>= (states+1)/2){
cout<<"1\n";
continue;
}
ans=0;
for(i=1;i<dist;i++)
{
total=0;
for(j=0;j<states;j++)
{
x=((j*dist)+i-1)%len;
y=(dist*(j+1)+i-1)%len;
/*DEBUG(x);
DEBUG(y);*/
state[j]= state[j] - a[x] + a[y];
if(state[j]>= (dist+1)/2){
total+=1;
}
///DEBUG(state[j]);
}
/*DEBUG(total);
cout<<endl;*/
if(total>= (states+1)/2){
ans=1;
break;
}
}
cout<<ans<<endl;
}
return 0;
}