You are viewing a single comment's thread. Return to all comments →
For those not interested using a bitset they can try this instead..clears all test cases
import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int m = in.nextInt(); int topicsMax = -1; int teams = 0; int noTopics = 0; int count = 0; String topic[] = new String[n]; for(int topic_i=0; topic_i < n; topic_i++){ topic[topic_i] = in.next(); } for(int j = 0; j < n; j++) { for(int k = j + 1; k < n; k++) { count = 0; for(int i = 0; i < m; i++) { if((topic[k].charAt(i) != topic[j].charAt(i)) || (topic[k].charAt(i) == '1' && topic[j].charAt(i) == '1')) { count++; } } if(count > topicsMax) { topicsMax = count; teams = 1; } else if(count == topicsMax) { teams++; } } } System.out.println(topicsMax); System.out.println(teams); } }
Seems like cookies are disabled on this browser, please enable them to open this website
ACM ICPC Team
You are viewing a single comment's thread. Return to all comments →
For those not interested using a bitset they can try this instead..clears all test cases