ACM ICPC Team

ACM ICPC Team

There are a number of people who will be attending ACM-ICPC World Finals. Each of them may be well versed in a number of topics. Given a list of topics known by each attendee, you must determine the maximum number of topics a 2-person team can know. Also find out how many ways a team can be formed to know that many topics. Lists will be in the form of bit strings, where each string represents an attendee and each position in that string represents a field of knowledge, 1 if its a known field or 0 if not.

For example, given three attendees’ data as follows:

1
2
3
10101
11110
00010

These are all possible teams that can be formed:

1
2
3
4
Members Subjects
(1,2) [1,2,3,4,5]
(1,3) [1,3,4,5]
(2,3) [1,2,3,4]

In this case, the first team will know all 5 subjects. They are the only team that can be created knowing that many subjects.

Function Description

Complete the acmTeam function in the editor below. It should return an integer array with two elements: the maximum number of topics any team can know and the number of teams that can be formed that know that maximum number of topics.

acmTeam has the following parameter(s):

  • topic: a string of binary digits

Input Format

The first line contains two space-separated integers n and m, where n represents the number of attendees and m represents the number of topics.

Each of the next n lines contains a binary string of length m. If the ith line’s jth character is 1, then the ith person knows the jth topic.

Constraints

2 <= n <= 500

1 <= m <= 500

Output Format

On the first line, print the maximum number of topics a 2-person team can know.

On the second line, print the number of ways to form a 2-person team that knows the maximum number of topics.

Sample Input

1
2
3
4
5
4 5
10101
11100
11010
00101

Sample Output

1
2
5
2

Explanation

Calculating topics known for all permutations of 2 attendees we get:

(1,2) -> 4

(1,3) -> 5

(1,4) -> 3

(2,3) -> 4

(2,4) -> 4

(3,4) -> 5

The 2 teams (1, 3) and (3, 4) know all 5 topics which is maximal.


Solution

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Complete the acmTeam function below.
function acmTeam(topic) {
let results = [];
let range = topic.length - 1;

for (let i of Array.from({ length: range }, (value, index) => index)) {
results.push(
...Array.from(
{ length: range - i },
(value, index) => index + 1 + i
).reduce((target, compare) => {
target.push(
[...topic[i]].reduce((target, item, valueIndex) => {
(!!+item || !!+topic[compare][valueIndex]) && target++;

return target;
}, 0)
);

return target;
}, [])
);
}

return results
.sort()
.reverse()
.reduce(
(target, item, index) => {
!index && (target[0] = item);

target[0] == item && target[1]++;

return target;
},
[0, 0]
);
}
Buy Me A Coffee

Comments

10Days of JS 30Days of Code Algorithm Android Debug Bridge Android Debugging Basic for Web Blog Browsers Chrome으로 Android Debugging 방법 Correctness and the Loop Invariant hackerrank solution in javascript Debug Tools Development Environment in MacOS ES6 Front-End Funny String of Algorithms hackerrank solution in javascript Funny String of Algorithms hackerrank solution in typescript Generator Github Page with Hexo Github Pages HackerRank HackerRank in a String of Algorithms hackerrank solution in javascript HackerRank in a String of Algorithms hackerrank solution in typescript Hexo Hexo Icarus theme Hexo 블로그 만들기 Hexo+Github How Browsers work Insertion Sort - Part 1 hackerrank solution in javascript Insertion Sort - Part 2 hackerrank solution in javascript JS Library JavaScript Level1 Level2 Loops MacOS 개발 환경 설정하기 Mobile web Debugging Node.js Pangrams of Algorithms hackerrank solution in javascript Pangrams of Algorithms hackerrank solution in typescript Problem Solving Programmers Quicksort 1 - Partition hackerrank solution in javascript React RoadMap Running Time of Algorithms hackerrank solution in javascript Safari Debugging Safari Technology Preview Settings Sorting String Strings Strong Password of Algorithms hackerrank solution in javascript TypeScript blog iPhone Safari Debugging 방법 insertion sort 모바일 웹 디버깅 아이폰 사파리를 디버깅하는 방법 안드로이드 디버그 브리지 안드로이드 디버깅하는 방법
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×