记录编号 39443 评测结果 AAAAAAAAAAAA
题目名称 平衡奶牛 最终得分 100
用户昵称 GravatarCC 是否通过 通过
代码语言 C++ 运行时间 0.426 s
提交时间 2012-07-11 16:28:17 内存使用 14.04 MiB
显示代码纯文本
#include <cstdio>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;
int n,K,ans;
int a[100005],s[100005][35];
vector<int> style;
map<vector<int>,int> f;
void work(int pos,int u) {
    for (int i = 1;i <= K;i++) {
        if (u & 1) s[pos][i] = s[pos - 1][i] + 1;
        else s[pos][i] = s[pos - 1][i];
        u >>= 1;
    }
}
int main() {
	freopen("balline.in","r",stdin);
	freopen("balline.out","w",stdout);
	scanf("%d%d", &n, &K);
	for (int i = 1;i <= n;i++) {
		scanf("%d", &a[i]);
		work(i,a[i]);
	}
	for (int i = 1;i <= K;i++) style.push_back(0);
	f[style] = 0;
	ans = 0;
	for (int i = 1;i <= n;i++) {
		style.clear();
		style.push_back(0);
		for (int j = 2;j <= K;j++) 
			style.push_back(s[i][j] - s[i][1]);
		if (f.count(style)) {
			int u = f[style];
			ans = std::max(ans,i - u);
			continue;
		}
		f[style] = i;
	}
	printf("%d\n", ans);
	return 0;
}