THEATRE - Editorial

Yes, but it’s unnecessary.

@tmwilliamlin thanks! I understood my error

yes, sure. But I gave it a try and I can’t get past the subtask 2. My solution here: CodeChef: Practical coding for everyone. I have tried multiple inputs.
Any help would be great.

@cpaddict I am first checking the permutations for what movies to play in each slot and then permutations for prices for each slot. Also, the solution is working for the given test cases and also custom inputs. Can anyone give me some cases where the solution would fail?

I’m not familiar with Hungarian Algorithm, so I can’t really help you with that.

don’t know why people want to solve a straightforward brute force div2 only problem by hungarian algo and also brute works faster (4!<4^3)

2 Likes

can someone please tell why I am not getting a 100 for this
[CodeChef: Practical coding for everyone]

My solution passes this test case but still it is partially accepted.

https://www.codechef.com/viewsolution/29906579

can someone tell while using maps data structure and somewhat same principle as used in the editorial why am i getting the runtime time limit exceeded error ?
How can fix this that too by using the maps DS ?

this is my code :
#include
#include
#include
#include
using namespace std;

// this template returns the pair to the key and value of the max value stored in a map 
template<typename KeyType, typename ValueType> 
std::pair<KeyType,ValueType> get_max( const std::map<KeyType,ValueType>& x ) {
  using pairtype=std::pair<KeyType,ValueType>; 
  return *std::max_element(x.begin(), x.end(), [] (const pairtype & p1, const pairtype & p2) {
        return p1.second < p2.second;
  }); 
}


// function maximum is used to return max of all the 4 the max vales of the 4 maps;
short int maximum(short int a, short int b, short int c, short int d){
int ret;
a = max(a,b);
b = max(a,c);
ret = max(b,d);
return ret;
}


// {{  My BASIC APPROACH IS DESCRIBD HERE }}


/*
function2 does a series of tasks comprising 
1. first get the max value of all the 4 max values of each map using maximum function adn storing it in max_here variable
2. matching this value of max_here with max value of each map (EAch map stores counts for different movies to be viewed at a specific time skot lets say 3pm)
3. then suppose the max value mathces with the max vlue of map_3 so we dop these steps
 3 - a. store the value of max value in map_3 in another variable as it will be used later fopr profit 
 3 - b. get the key's name and then set all values for that key in each of maps as -1 (so that next time this movie wwon't come out in the maximum function)
 3 - c. then set that map whih had the maximum count i.e. map_3 all values to -1 (so that this slot won't come in  maximum function nxt time)

*/


 int function2(std::map<char, int>& temp3_map , std::map<char, int>& temp6_map, std::map<char, int>& temp9_map, std::map<char, int>& temp1_map ){
    auto max1=get_max(temp3_map);
    auto max2=get_max(temp6_map);     
    auto max3=get_max(temp9_map);
    auto max4=get_max(temp1_map);      // getting max values of each map
    short int maxx; // maxx will be retuned in the end
    char a;
    short int max_here =  maximum(max1.second,max2.second,max3.second,max4.second); // find the max of all 4 maps
    
    if (max1.second == max_here){
        //default code here
        maxx= max1.second;    // getting value of the max count of all sets into the maxx (a temporary variable)

        temp3_map.at('A') = -1;
        temp3_map.at('B') = -1;
        temp3_map.at('C') = -1;
        temp3_map.at('D') = -1;
        a = max1.first;
        temp6_map.at(a) = -1;
        temp9_map.at(a) = -1;        
        temp1_map.at(a) = -1; // in these three lines set (like every set's A to -1)
    }
    
    else if(max2.second ==max_here){
        //default code here
        maxx= max2.second;    // getting value of the max count of all sets into the maxx

        temp6_map.at('A') = -1;
        temp6_map.at('B') = -1;
        temp6_map.at('C') = -1;
        temp6_map.at('D') = -1;
        a = max2.first;
        temp3_map.at(a) = -1;
        temp9_map.at(a) = -1;        
        temp1_map.at(a) = -1;
    }
    
    else if(max3.second ==max_here){
        //default code here
        maxx= max3.second;    // getting value of the max count of all 4 maps into the maxx
        
        temp9_map.at('A') = -1;
        temp9_map.at('B') = -1;
        temp9_map.at('C') = -1;
        temp9_map.at('D') = -1;
        a = max3.first;
        temp3_map.at(a) = -1;
        temp6_map.at(a) = -1;        
        temp1_map.at(a) = -1;
    }
    
    else {
        maxx= max4.second;    // getting value of the max count of all 4 maps into the maxx
        
        temp1_map.at('A') = -1;
        temp1_map.at('B') = -1;
        temp1_map.at('C') = -1;
        temp1_map.at('D') = -1;
        a = max4.first;
        temp3_map.at(a) = -1;
        temp6_map.at(a) = -1;        
        temp9_map.at(a) = -1;
    }

    return maxx;
}



int main() {
    int T,N;
    //initially declaring the maps
   // EAch map stores counts for different movies to be viewed at a specific time skot lets say 3pm
        std::map<char, int> temp3_map; // map for storing  movie times at 3 pm 
        std::map<char, int> temp6_map; // map for storing  movie times at 6 pm
        std::map<char, int> temp9_map; // map for storing  movie times at 9 pm   
        std::map<char, int> temp1_map; // map for storing  movie times at 12 pm
        
        
    cin>>T;
    int total = 0 ;
    for(int k= 0;k<T; k++ ){
     int sum= 0;    
// Let's first set all map values to zero
    temp3_map['A'] = 0;
    temp3_map['B'] = 0; temp3_map['C'] = 0; temp3_map['D'] = 0; // for 3 pm ))--- map setting all to 0 
    
    temp6_map['A'] = 0;
    temp6_map['B'] = 0; temp6_map['C'] = 0; temp6_map['D'] = 0; // for 6 pm ))--- map setting all to 0
    
    temp9_map['A'] = 0;
    temp9_map['B'] = 0; temp9_map['C'] = 0; temp9_map['D'] = 0; // for 9 pm ))--- map setting all to 0
    
    temp1_map['A'] = 0;
    temp1_map['B'] = 0; temp1_map['C'] = 0; temp1_map['D'] = 0; // for 12 pm ))--- map setting all to 0


     cin>>N;
     for (int j =0; j<N; j++){
            char m;
            short int t;
            cin>>m;
            cin>>t;
            if (m == 'A'){
                switch (t)
{
    case 3:  
            temp3_map.at('A')++; 
            break; 
        case 6:  
            temp6_map.at('A')++; 
            break; 
        case 9:  
            temp9_map.at('A')++;
            break; 
        default:  
            temp1_map.at('A')++; 
            break;
}
            }
            
            else if (m == 'B'){     //  temp3_map['B'] = 0
                switch (t)
                {
    case 3:  
            temp3_map['B']++; 
            break; 
        case 6:  
           temp6_map['B']++; 
            break; 
        case 9:  
            temp9_map['B']++;
            break; 
        default:  
            temp1_map['B']++; 
            break;
}
            }
            
            else if (m == 'C'){
                switch (t)
{
    case 3:  
            temp3_map['C']++; 
            break; 
        case 6:  
            temp6_map['C']++; 
            break; 
        case 9:  
            temp9_map['C']++;
            break; 
        default:  
            temp1_map['C']++; 
            break;
}
            }
            
            else if (m == 'D'){
                switch (t)
{
    case 3:  
            temp3_map['D']++; 
            break; 
        case 6:  
            temp6_map['D']++; 
            break; 
        case 9:  
            temp9_map['D']++;
            break; 
        default:  
            temp1_map['D']++; 
            break;
}
            }
        }
        
for (int i =4 ; i>0;i--){
    int abc = function2(temp3_map,temp6_map,temp9_map,temp1_map);
    if (abc != 0)
    sum = sum + (25*i*abc);
    else
 sum = sum - 100; 
}
total = total + sum;
cout<<sum<<endl;
} // each testcase ends here
cout<<total;
return 0;
}

My solution passes this test case but still it is partially accepted.

https://www.codechef.com/viewsolution/29906579

Fails for this:

Test Case

1
24
A 12
A 9
A 9
A 9
B 12
B 12
B 9
B 9
B 9
B 9
C 12
C 12
C 3
C 3
C 3
C 6
C 6
D 3
D 3
D 3
D 3
D 6
D 6
D 6

Ans- 825

the link to my solution
https://www.codechef.com/viewsolution/29379198
it was partially accepted i can not figure it out why

Did u use it?

Can you please explain your solution?

I am unable to understand why i got only 30 points.
Please help.
[CodeChef: Practical coding for everyone]

https://www.codechef.com/viewsolution/29771611
This was my solution for which i got 30 points i would really appreciate if someone told me which testcases it doesnt satisfy.Sorry for posting this doubt so late.
Thanx in advance!

Coder==pro :slightly_smiling_face:

1 Like