#1702. [Usaco2007 Mar]Gold Balanced Lineup 平衡的队列

[Usaco2007 Mar]Gold Balanced Lineup 平衡的队列

题目描述

Farmer John's nn cows (1n105)(1 \le n \le 10^5) share many similarities. In fact, FJ has been able to narrow down the list of features shared by his cows to a list of only kk different features (1k30)(1 \le k \le 30). For example, cows exhibiting feature #1 might have spots, cows exhibiting feature #2 might prefer C to Pascal, and so on. FJ has even devised a concise way to describe each cow in terms of its "feature ID", a single k-bit integer whose binary representation tells us the set of features exhibited by the cow. As an example, suppose a cow has feature ID = 1313. Since 1313 written in binary is 11011101, this means our cow exhibits features 11, 33, and 44 (reading right to left), but not feature 22. More generally, we find a 11 in the 2i12^{i-1} place if a cow exhibits feature ii. Always the sensitive fellow, FJ lined up cows 1n1\dots n in a long row and noticed that certain ranges of cows are somewhat "balanced" in terms of the features the exhibit. A contiguous range of cows iji\dots j is balanced if each of the kk possible features is exhibited by the same number of cows in the range. FJ is curious as to the size of the largest balanced range of cows. See if you can determine it.

nn 头牛,一共 kk 种特色,每头牛有多种特色,用二进制 0101 表示它的特色 ID。比如特色 ID 为 13(1101)13(1101),则它有第 113344 种特色。[i,j][i,j] 段被称为 balanced 当且仅当 kk 种特色在 [i,j][i,j] 内拥有次数相同。求最大的 [i,j][i,j] 段长度。

输入格式

  • Line 11: Two space-separated integers, nn and kk.
  • Lines 2n+12\dots n+1: Line i+1i+1 contains a single kk-bit integer specifying the features present in cow ii. The least-significant bit of this integer is 11 if the cow exhibits feature #1, and the most-significant bit is 11 if the cow exhibits feature #k.

输出格式

  • Line 11: A single integer giving the size of the largest contiguous balanced group of cows.
7 3
7
6
7
2
1
4
2
4

样例说明

INPUT DETAILS:
The line has 77 cows with 33 features; the table below summarizes the correspondence:

Feature 33: 11 00 11 00
Feature 22: 11 11 11 11 00 00 11
Feature 11: 00 00 11 00
key: 77 66 77 22 44 22
Cow #: 11 22 33 44 55 66 77

OUTPUT DETAILS:
In the range from cow #3 to cow #6 (of size 44), each feature appears in exactly 22 cows in this range:

Feature 33: 11 00 11 -> two total
Feature 22: 11 11 00 00 -> two total
Feature 11: 00 11
key: 77 22 44
Cow #: 33 44 55 66

数据规模与约定

对于 100%100\% 的数据,1n1051\le n\le10^51k301\le k\le30

题目来源

鸣谢fjxmyzwd

Gold