CHEFWED - Editorial

What is the wrong with this solution , Why the test case 2 is not “AC” successfully.

1 Like

I can’t see Setter’s solution.

You were so close :open_mouth:

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

This is my solution (JAVA). I didn’t use DP, but more of a brute force approach. Got AC✔ (100 pts) .

@rishup_nitdgp Can you review my approach?

2 Likes

But i don’t know what is wrong.

Without use of dp, i did it by hashing only
https://www.codechef.com/viewsolution/36753378

3 Likes

My solution is giving me WA in 2nd subtask’s first and second cases.

CodeChef: Practical coding for everyone, I haven’t used DP

Could you please give me an example of a test case for this category.

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

I am also getting same let me know if u r getting test case

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

Its n^3 complexity code, the best I could muster but understandable (at least for me) nonetheless.

me too

time complexity should be 100 x (n^2) x (log100 for using map) = 6 x 10^8, now can anyone explain this to me that why is this dp solution is passing in 1 sec???

This code is giving Segmentation fault on my computer.

1 Like

test case please ?
maybe that is what i will have to think about
coz u can also see that it is passing all except 3 test cases

No test case. It directly crashed.

it cannot happen !! i just submit this code on codechef for this problem submission…
fyi it is cpp code

I made this in java for subtask of k=1; CodeChef: Practical coding for everyone
can someone help with test cases or logic that is wrong.

thanks :grin: i found where i went wrong

yeah,I was able to do it using recursion merely…Though it was exponential but I was able to realise the suitable length of array to apply recursion

1 Like

Naive approach here

1 Like

can anyone help me with this solution …it passed all the cases of subtask 1 and #5 of subtask 2

/* package codechef; // don’t place package name! */

import java.util.;
import java.lang.
;
import java.io.*;

/* Name of the class has to be “Main” only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner sc=new Scanner (System.in);
int t=sc.nextInt();
for(int i=0;i<t;i++)
{
int n=sc.nextInt();
int k=sc.nextInt();
int ar[]=new int[n];
for(int j=0;j<n;j++)
ar[j]=sc.nextInt();
int counter[]=new int[100];
int tolerance=0;
int ineff=k;
for(int j=0;j<n;j++)
{
counter[ar[j]-1]=counter[ar[j]-1]+1;
if(counter[ar[j]-1]>1)
{
if(counter[ar[j]-1]==2)
{
tolerance+=2;
ineff+= 2;
}
else
{
tolerance++;
ineff++;
}
}
if(tolerance>=k)
{
ineff=ineff+k-tolerance;
tolerance=0;
for(int p=0;p<100;p++)
counter[p]=0;
j–;
}
}
System.out.println(ineff);
}
}
}