Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //https://www.hackerrank.com/challenges/acm-icpc-team/problem?isFullScreen=true
- ll getOne ( string s ){
- ll count =0 ;
- for (auto x : s ){
- if ( x=='1') count++;
- }
- return count ;
- }
- vector<ll> acmTeam(vector<string> topic) {
- int len = topic[1].size();
- ll numTeams = 0 ;
- ll n= topic.size();
- vector < ll > res;
- for (int i=0;i<n;i++){
- for (int j= i+1;j<n;j++){
- string thisRecent ="";
- for (int l=0;l<len;l++){
- if (topic[i][l]=='0' && topic[j][l]=='0') {
- thisRecent+='0';
- }
- else if (topic[i][l]=='0' && topic[j][l]=='1' ){
- thisRecent+='1';
- }
- else if (topic[i][l]=='1' && topic[j][l]=='0' ){
- thisRecent+='1';
- }
- else if (topic[i][l]=='1' && topic[j][l]=='1' ){
- thisRecent+='1';
- }
- }
- ll count = getOne(thisRecent);
- res.push_back(count);
- }
- }
- ll maxx = -1 ;
- for (auto x : res ){
- maxx = max ( maxx, x );
- }
- for (auto x : res ){
- if ( x== maxx ){
- numTeams ++ ;
- }
- }
- vector < ll > rt ;
- rt.push_back(maxx);
- rt.push_back(numTeams);
- return rt;
- }
Advertisement
Add Comment
Please, Sign In to add comment