PROBLEM LINKDIFFICULTYsimple PREREQUISITESgeneral programming skills PROBLEMThere are $n$ islands, and $k$ ingredients numbered from $1$ to $k$. Each island contains some ingredients, let ${ingredient}_i$ denotes the list of ingredients in $i$th island. Chef wants to collect these ingredients from these islands. He wants to check following cases.
You have to identify which of these scenarios is there. Checking whether Chef can even collect the desired $k$ ingredients or not. This is same as checking whether is there some ingredient which is not present in any island. For each ingredient, we can maintain the number of islands it is present in. let $cnt[i]$ denote the number of islands in which the ingredient $i$ is present. We can check whether there is some ingredient whose $cnt$ value is zero or not.
Now, we know that it is possible to collect the $k$ ingredient. Now we should find whether Chef will need to visit all the $n$ islands for collecting these ingredients or not. If there is a ingredient $i$ which is present only in a single island, i.e. $cnt[i] = 1$, then you will have to definitely need to visit this island. Otherwise, you can skip this island, and collect the ingredients from remaining $n  1$ islands.
Time complexity of this algorithm will be equal to $\text{ingredient}1.\text{size}() \, + \, \text{ingredient}2.\text{size}() + \dots +\text{ingredient}[n].\text{size}()$. For solving the final subtask, we have the constraints over sum that it will not exceed $10^6$. Hence, it will take around $10^6$ operations for answering each test case. SETTER'S SOLUTIONCan be found here. TESTER'S SOLUTIONCan be found here.
This question is marked "community wiki".
asked 15 Apr '17, 22:09

Answer is hidden as author is suspended. Click here to view.
answered 20 Apr '17, 21:29

I request your scrutiny on this code https://www.codechef.com/viewsolution/13350172 . I would like to know areas it could be optimized in order for it to run faster and also to rid off SIGSEGV. The code runs well with the provided test cases but it fails the online judge test cases. answered 18 Apr '17, 00:56

i solved this question simply by using set. my solution https://www.codechef.com/viewsolution/13233163 answered 20 Apr '17, 20:54

Hi, Can anyone please explain why I'm getting the last 2 cases wrong? I implemented the same logic as in the editorial. answered 17 Apr '17, 16:52
While checking; if (cnt[islands[i][j]] == 1), add a break condition inside the if condition. Your solution woundn't work for this test case; n = 3, k = 4, {1,4}, {2,3}, {4}. In your case, answer would be "all" since v=3 (v==n). But, clearly it should be "some".
(17 Apr '17, 18:53)
Here's, my very similar solution: https://www.codechef.com/viewsolution/13218833
(17 Apr '17, 18:55)
Great, I understood. Thank you for your help!
(17 Apr '17, 20:23)

Links to setter's solution and tester's solution are not working, please fix this. answered 17 Apr '17, 21:20

there is something wrong in the last statement I see "Time complexity of this algorithm will be equal to $\text{ingredient}....." Also the setters solution and testers solution are not working, please fix it answered 18 Apr '17, 09:34

If the input is
or if it is
The answer in both the cases should be "some". Because for the 1st case we can skip 2nd or 3rd island and for the 2nd case we can skip 1st or 2nd island. But the judge is accepting solutions in which for the first case o/p is "some" and for the second case o/p is "all". This is the case if someone is starting from the first island and iterating over all the island one by one and checking if at any island(not the last one) all the ingredients are covered or not. But this is the wrong approach. answered 18 Apr '17, 20:50

include <stdio.h>int main() {
} I dont understand why this code works(100 marks) bcoz no. of columns in array b[100000][5] which is used to store ingredients of a particular island is of size 5 only still code works for original constraints?Why plz explain. answered 19 Apr '17, 12:30

In my solution 2nd test case getting failed because of TLE. https://www.codechef.com/viewsolution/13274266 Please anyone let me know, how I can improve. Thanks answered 20 Apr '17, 18:37

I think the judge for this problem is incorrect. Consider the following input: 1 2 3 2 1 3 2 1 2 The answer should be 'all'. My solution which prints "all" Another solution which prints "some" Both solutions were passed by the judge giving both the solutions 100 points. answered 10 May '17, 11:30

can anyone tell me whats wrong wid my code..... link : https://www.codechef.com/viewsolution/14232897 i have done using adjecancy matrix !! answered 12 Jun '17, 11:50
Reason you are getting run time error is that you have created matrix[n][k] and you are accessing matrix[n][k] while the max you can access is matrix[n1][k1]. As far as TLE is concerned I think your solution is O(N^3).
(12 Jun '17, 14:21)

I dont have enough karma to ask a question, that's why i am posting my code here. i don't know whats wrong with this,please help!!! include<bits stdc++.h="">using namespace std; int main() { int t; cin>>t; while(t) { int n,k; cin>>n>>k; int p,ele,ele_count=0; int i,flag2=0;
} } answered 15 Jul '17, 23:48
