You are viewing a single comment's thread. Return to all comments →
C++ solution but it's O(n^2), idk if it's possible to achieve lower complexity:
vector<int> acmTeam(vector<string> topic) { int max_knowledge{0}, teams_max_knowledge{0}; for (int i=0; i<topic.size(); i++){ bitset<500> i_bitset (topic[i]); for (int j=i+1; j<topic.size(); j++){ bitset<500> j_bitset (topic[j]); string bitwise_or = (i_bitset | j_bitset).to_string(); int team_knowledge = count(bitwise_or.begin(), bitwise_or.end(), '1'); if (team_knowledge > max_knowledge){ max_knowledge = team_knowledge; teams_max_knowledge = 1; } else if (team_knowledge == max_knowledge) teams_max_knowledge++; } } return vector<int> {max_knowledge, teams_max_knowledge}; }
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 →
C++ solution but it's O(n^2), idk if it's possible to achieve lower complexity: