forked from marioyc/Online-Judge-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3274 - Gold Balanced Lineup.cpp
58 lines (37 loc) · 1.05 KB
/
3274 - Gold Balanced Lineup.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
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
pair<unsigned long long, int> a[100001];
int main(){
int N,K;
scanf("%d %d",&N,&K);
vector<int> aux(K,0);
a[0] = make_pair(0,0);
for(int i = 0,x;i < N;++i){
scanf("%d",&x);
for(int j = 0;j < K;++j)
if(x & (1 << j))
++aux[j];
int mn = aux[0];
for(int j = 1;j < K;++j)
mn = min(mn,aux[j]);
for(int j = 0;j < K;++j)
aux[j] -= mn;
unsigned long long H = 0;
for(int j = 0;j < K;++j)
H = H * 100005 + aux[j];
a[i + 1] = make_pair(H,i + 1);
}
sort(a,a + (N + 1));
int ans = 0;
for(int i = 0;i < N + 1;){
int e = i;
while(e < N + 1 && a[e].first == a[i].first) ++e;
ans = max(ans,a[e - 1].second - a[i].second);
i = e;
}
printf("%d\n",ans);
return 0;
}