天天看點

P1360 [USACO07MAR]Gold Balanced Lineup G

​​傳送門​​

P1360 [USACO07MAR]Gold Balanced Lineup G

題意:

思路:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define pb push_back 
#define p push
const int mod = 1e8;
ll n,m;
vector<ll>now[100010];
map<vector<ll>,int>vis;

int main()
{
//  freopen("C:\\Users\\76004\\Downloads\\P1360_1.in","r",stdin);
  cin>>n>>m;
  int ans = 0;
  for(int i = 0; i < m; i++)
  {
    now[1].pb(0);
    vis[now[1]] = 1;
  }
  for(int i = 2; i <= n+1; i++)
  {
    ll x;
    cin>>x;
    for(int j = 0; j < m; j++)
    {
      int b = x%2;x>>=1;
      now[i].pb(b);
//      if(i>2)
      now[i][j]+=now[i-1][j];
//      cout<<now[i][j]<<" ";
    }
//    cout<<endl;
    vector<ll>p;
    for(int j = 0; j < m; j++)
    p.pb(now[i][j]-now[i][0]);
    if(vis[p])ans = max(ans,i-vis[p]);
    else vis[p] = i;
  }
  cout<<ans<<endl;
}