Sort by

recency

|

1251 Discussions

|

  • + 0 comments

    This is so over the top, but I refuse to do it otherwise

    class BinaryString {
    public:
        std::string value;
    
        BinaryString(const std::string& bin_str) : value(bin_str) {}
    
        // Overload the + operator
        BinaryString operator+(const BinaryString& other) const {
            std::string result = "";
            
            for (int i = 0; i<value.size(); i++) {
                if(value[i]=='1' || other.value[i]=='1'){
                    result+="1";
                }
            }
            std::reverse(result.begin(), result.end());
            return BinaryString(result);
        }
    };
    
    
    
    vector<int> acmTeam(vector<string> topic) {
        int subjects = 0;
        int knowitalls = 0;
        std::vector<BinaryString> teams;
        std::transform(topic.begin(), topic.end(), std::back_inserter(teams), [](const std::string& s) { return BinaryString(s); });
        
        for(int i = 0; i<teams.size(); i++){
            for(int j = i+1; j<teams.size(); j++){
                 BinaryString team_sum = teams[i] + teams[j];
                 
                 if(team_sum.value.size()>subjects){
                    subjects = team_sum.value.size();
                    knowitalls = 0;
                 }
                 
                if(team_sum.value.size()==subjects){
                    knowitalls++;
                 }
            }
        }
        
        
        return {subjects, knowitalls};
    }
    
  • + 0 comments

    def acmTeam(topic): # Write your code here combs = [ sum([ 1 if i=='1' or j=='1' else 0 for i, j in zip(s1, s2)]) for s1, s2 in combinations(topic, 2)] key_value = sorted(Counter(combs).items())[-1] return list(key_value)

  • + 0 comments

    my kotlin solution

    fun knownTopics(topic1 : String,topic2 : String) : Int{
        var res = 0
        for(t in 0..topic1.length-1){
            if(topic1.get(t) == '1' || topic2.get(t) == '1')
                res++
        }
        return res
    }
    /*
     * Complete the 'acmTeam' function below.
     *
     * The function is expected to return an INTEGER_ARRAY.
     * The function accepts STRING_ARRAY topic as parameter.
     */
    
    fun acmTeam(topics: Array<String>): Array<Int> {
        // Write your code here
        var scores = mutableListOf<Int>()
        for(i in 0..topics.size-2){
            var p1 = topics.get(i)
            for(j in i+1..topics.size-1){
                var p2 = topics.get(j)
                scores.add(knownTopics(p1, p2))
            }
        }
        scores.sortDescending()
        var res = Array<Int>(2){0;0}
        res[0]=scores.get(0)
        res[1]=scores.count{
            it == res[0]
        }
        return res
    }
    
  • + 0 comments

    import java.io.; import java.util.; import java.util.stream.*; import static java.util.stream.Collectors.joining; import static java.util.stream.Collectors.toList;

    class Result {

    public static List<Integer> acmTeam(List<String> topic) {
        int maxTopics = 0;
        int teamCount = 0;
    
        for (int i = 0; i < topic.size(); i++) {
            for (int j = i + 1; j < topic.size(); j++) {
                String personA = topic.get(i);
                String personB = topic.get(j);
    
                int knownTopics = 0;
                for (int k = 0; k < personA.length(); k++) {
                    if (personA.charAt(k) == '1' || personB.charAt(k) == '1') {
                        knownTopics++;
                    }
                }
    
                if (knownTopics > maxTopics) {
                    maxTopics = knownTopics;
                    teamCount = 1;
                } else if (knownTopics == maxTopics) {
                    teamCount++;
                }
            }
        }
    
        return Arrays.asList(maxTopics, teamCount);
    }
    

    }

    public class Solution { public static void main(String[] args) throws IOException { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));

        String[] firstMultipleInput = bufferedReader.readLine().replaceAll("\\s+$", "").split(" ");
        int n = Integer.parseInt(firstMultipleInput[0]);
        int m = Integer.parseInt(firstMultipleInput[1]);
    
        List<String> topic = IntStream.range(0, n).mapToObj(i -> {
            try {
                return bufferedReader.readLine();
            } catch (IOException ex) {
                throw new RuntimeException(ex);
            }
        }).collect(toList());
    
        List<Integer> result = Result.acmTeam(topic);
    
        bufferedWriter.write(
            result.stream()
                .map(Object::toString)
                .collect(joining("\n")) + "\n"
        );
    
        bufferedReader.close();
        bufferedWriter.close();
    }
    

    }

  • + 0 comments

    The time constraints on these test cases are too tight. As in: for a C# solution, the additional time spent to instantiate variables at the start of the method for use and to increase code clarity, something even Exclaimer would value, rather than using the indices of the List being returned, is enough extra time to cause multiple test cases to fail. Grease Monkey Direct Integer instantiation takes a few microseconds. That's completely unreasonable. Insane, even.