tungggg

/acm-icpc-team

May 23rd, 2022
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.36 KB | None | 0 0
  1. //https://www.hackerrank.com/challenges/acm-icpc-team/problem?isFullScreen=true
  2.  
  3. ll getOne ( string s ){
  4.    ll count =0 ;
  5.     for (auto x : s ){
  6.         if ( x=='1') count++;
  7.     }
  8.     return count ;
  9. }
  10.  
  11. vector<ll> acmTeam(vector<string> topic) {
  12.     int len = topic[1].size();
  13.     ll numTeams = 0 ;
  14.     ll n= topic.size();
  15.     vector < ll  > res;
  16.     for (int  i=0;i<n;i++){
  17.         for (int j= i+1;j<n;j++){
  18.             string thisRecent ="";
  19.             for (int l=0;l<len;l++){
  20.                 if (topic[i][l]=='0' && topic[j][l]=='0') {
  21.                     thisRecent+='0';
  22.                 }
  23.                 else if (topic[i][l]=='0' && topic[j][l]=='1' ){
  24.                     thisRecent+='1';
  25.                 }
  26.                 else if (topic[i][l]=='1' && topic[j][l]=='0' ){
  27.                     thisRecent+='1';
  28.                 }
  29.                 else if (topic[i][l]=='1' && topic[j][l]=='1' ){
  30.                     thisRecent+='1';
  31.                 }
  32.             }
  33.             ll count = getOne(thisRecent);
  34.             res.push_back(count);
  35.         }
  36.        
  37.     }
  38.     ll maxx = -1 ;
  39.     for (auto x : res ){
  40.         maxx = max ( maxx, x );
  41.     }
  42.     for (auto x : res ){
  43.         if ( x== maxx ){
  44.             numTeams ++ ;
  45.         }
  46.     }
  47.     vector < ll > rt ;
  48.     rt.push_back(maxx);
  49.     rt.push_back(numTeams);
  50.     return rt;
  51. }
  52.  
Advertisement
Add Comment
Please, Sign In to add comment