#include<stdio.h>
#include<malloc.h>
#include<string.h>
#define prime 9773
typedef struct A
{
int index;
struct A *next;
}A;
int distance = 0;
int map[100001][30]={0};
A *Hash[prime] = {0};
//K为牛特点的个数
void find(int cowCount,int K);
int cmp(int srci,int index,int K);
int getHash(int index,int K);
int getHash(int index,int K)
{
int j;
int hash = 1;
for(j=0; j<K; j++)
hash = hash*7 + map[index][j];
hash = (hash<0 ? -hash : hash) % prime;
return hash;
}
int cmp(int srci,int index,int K)
{
//比较srci与index中的内容
int i;
for(i=0; i<K && map[srci][i] == map[index][i]; i++)
;
return i==K;
}
void find(int cowCount,int K)
{
int i;
int hash;
A *p;
//注册
for(i=0; i<=cowCount; i++)
{
hash = getHash(i,K);
p = Hash[hash];
while(p)
{
//存在
if( cmp(i,p->index,K) )
{
//更新distance
if(i - (p->index) > distance)
{
distance = i - (p->index);
}
break;
}
p = p->next;
}
if(!p)
{
p = (A *)malloc(sizeof(A) * 1);
p->index = i;
p->next = Hash[hash];
Hash[hash] = p;
}
}
printf("%d\n",distance);
}
int main(void)
{
int tedian;
int i,j;
int N,K;//N牛数量,K特点的数目
memset(Hash,0,sizeof(A *)*prime);
memset(map,0,sizeof(int)*100000*30);
scanf("%d%d",&N,&K);
//初始化map
for(i=1; i<N+1; i++)
{
scanf("%d",&tedian);
for(j=0; j<K; j++)
map[i][j] = (tedian & (1<<j) ? 1 : 0);
}
//叠加
for(i=1; i<=N; i++)
for(j=0; j<K; j++)
map[i][j] = map[i][j] + map[i-1][j];
//减
for(i=1; i<=N; i++)
for(j=K-1; j>=0; j--)
map[i][j] = map[i][j]-map[i][0];
find(N,K);
}
#include<malloc.h>
#include<string.h>
#define prime 9773
typedef struct A
{
int index;
struct A *next;
}A;
int distance = 0;
int map[100001][30]={0};
A *Hash[prime] = {0};
//K为牛特点的个数
void find(int cowCount,int K);
int cmp(int srci,int index,int K);
int getHash(int index,int K);
int getHash(int index,int K)
{
int j;
int hash = 1;
for(j=0; j<K; j++)
hash = hash*7 + map[index][j];
hash = (hash<0 ? -hash : hash) % prime;
return hash;
}
int cmp(int srci,int index,int K)
{
//比较srci与index中的内容
int i;
for(i=0; i<K && map[srci][i] == map[index][i]; i++)
;
return i==K;
}
void find(int cowCount,int K)
{
int i;
int hash;
A *p;
//注册
for(i=0; i<=cowCount; i++)
{
hash = getHash(i,K);
p = Hash[hash];
while(p)
{
//存在
if( cmp(i,p->index,K) )
{
//更新distance
if(i - (p->index) > distance)
{
distance = i - (p->index);
}
break;
}
p = p->next;
}
if(!p)
{
p = (A *)malloc(sizeof(A) * 1);
p->index = i;
p->next = Hash[hash];
Hash[hash] = p;
}
}
printf("%d\n",distance);
}
int main(void)
{
int tedian;
int i,j;
int N,K;//N牛数量,K特点的数目
memset(Hash,0,sizeof(A *)*prime);
memset(map,0,sizeof(int)*100000*30);
scanf("%d%d",&N,&K);
//初始化map
for(i=1; i<N+1; i++)
{
scanf("%d",&tedian);
for(j=0; j<K; j++)
map[i][j] = (tedian & (1<<j) ? 1 : 0);
}
//叠加
for(i=1; i<=N; i++)
for(j=0; j<K; j++)
map[i][j] = map[i][j] + map[i-1][j];
//减
for(i=1; i<=N; i++)
for(j=K-1; j>=0; j--)
map[i][j] = map[i][j]-map[i][0];
find(N,K);
}