#P12245. 共同兴趣

    ID: 11693 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 3 上传者: 标签>模拟洛谷原创O2优化洛谷月赛

共同兴趣

Description

There are nn students in Little O's grade, numbered 1n1 \sim n. The school surveyed mm activities. Each student is interested in some activities and not in others. Let ai,ja_{i,j} indicate whether student ii is interested in activity jj, where ai,j=1a_{i,j} = 1 means interested and ai,j=0a_{i,j} = 0 means not interested.

For any two students ii and jj, their number of common interests is the count of activities kk where ai,k=aj,k=1a_{i,k} = a_{j,k} = 1, i.e., the number of activities both students are interested in.

Each student xx will find all students yy who have the maximum number of common interests with xx and send them friendship invitations. If multiple students yy satisfy this condition, xx will send invitations to all of them.

Little O (student 11) wants to receive as many invitations as possible. He can choose one activity ii where he is not initially interested (i.e., a1,i=0a_{1,i} = 0) and change it to a1,i=1a_{1,i} = 1. He may also choose not to modify any activity. Note: At most one modification is allowed.

What is the maximum number of students who will send invitations to Little O after making at most one modification?

Input Format

The input consists of n+1n+1 lines:

  • Line 11: Two integers nn and mm, representing the number of students and activities.
  • Lines 22 to n+1n+1: Each line contains mm integers. The jj-th integer in line i+1i+1 represents ai,ja_{i,j}.

Output Format

Output one integer: the maximum number of students who will invite Little O.

3 3
0 0 0 
1 0 1
0 1 1
2
4 3
0 0 0 
1 0 1
0 1 1
1 1 1
0

Hint

Sample #1 Explanation

Initially, students 22 and 33 each have 11 common interest with each other (activity 33). Their common interests with Little O are 00. Modifications:

  • No modification: 00 invitations.
  • Modify a1,1a_{1,1} to 11: Student 22 invites Little O (11 invitation).
  • Modify a1,2a_{1,2} to 11: Student 33 invites Little O (11 invitation).
  • Modify a1,3a_{1,3} to 11: Both students 22 and 33 invite Little O (22 invitations).

Thus, the maximum is 22.

Sample #2 Explanation

Adding student 44 (who has 22 common interests with students 22 and 33). Little O's maximum common interests with any student after modification cannot exceed 11, so the answer is 00.

For 100%100\% data:

  • 2n5002 \le n \le 500
  • 1m5001 \le m \le 500
  • ai,j{0,1}a_{i,j} \in \{0,1\}
Test Case nn Range mm Range Special Properties
11 n=2n=2 m50m \le 50 None
242\sim 4 n50n \le 50
565\sim 6 n500n \le 500 m=1m=1 A
7107\sim 10 m500m \le 500
111411\sim 14 B
152015\sim 20 None

Special Properties:

  • A: For all 1im1 \le i \le m, a1,i=0a_{1,i} = 0.
  • B: For all 1in1 \le i \le n, ai,1=0a_{i,1} = 0.