Problem **Chef and Cook-Off Contests**

Problem

To find whether any subset of given problems can form a particular set.

**Observation**:All the different types of problems can be checked independently of each other…

So, for this problem, it is sufficient to check if given problem set contains atleast one cakewalk, one easy, one simple, one medium or easy-medium and one medium or medium hard…

You may have a look at my code here…

Problem **Chef and Dice**

Following a set of turns, we have to find a valid dice configuration and output in the format

**O(1)** … where O(1) means Opposite side of 1 … (I wasted half an hour on this today )

**Observation**: Here, the number which appear on ith turn will never be opposite to the number which appear on (i-1)th turn as well as (i+1)th turn…

If Number at ith turn == Number at (i+1)th turn, ans is -1

So, This is all we need for this problem…

Using this information, we run the brute-force algorithm (Because sides of dice are 6 only, our solution won’t get TLE)

pseudocode

adj[i][j] is a boolean table where adj[i][j] = true if i and j are adjacent, else false

```
int i1 = 1; // Select any vertex
for(int i = 1; i<=6; i++){
//condition for selecting a candidate for opposite vertex
if(i != i1 && !adj[i1][i]){
boolean[] v = new boolean[7]; // keeping track of sides visited
int i2 = i; //opposite of i1
v[i1] = true; //marked these two as visited
v[i2] = true;
for(int j = 1; j<= 6; j++){
if(!v[j]){ //Selecting another non-selected side
int i3 = j;
v[i3] = true;
//finding opposite in this loop
for(int k = 1; k<= 6; k++){
if(!adj[i3][k] && !v[k]){
v[k] = true;
int i4 = k;
for(int l = 1; l<= 6; l++){
if(!v[l]){
int i5 = l;
v[i5] = true;
int i6 = 21 - i1-i2-i3-i4-i5;
if(i6>0 && i6 < 7 && !v[i6] && !adj[i6][i5]){
int[] opp = new int[7];// opp[i] = side opposite to i
opp[i1] = i2;
opp[i2] = i1;
opp[i3] = i4;
opp[i4] = i3;
opp[i5] = i6;
opp[i6] = i5;
String out = "";
for(int m = 1; m<= 6; m++)out += opp[m]+" ";
print(out);
break case;
}
v[i5] = false; // unmarking this side for next candidate
}
}
v[k] = false;
}
}
v[i3] = false;
}
}
}
}
print(-1); // in case no permutation satisfies the constraints
```

Have a look at my solution here.

I didn’t get the full scores in last 2 problems, so, It’s better to refer to official editorial…

Hope you all find this helpful