COVIDLQ - Editorial

My subtask is giving correct output , i tried various inputs too but still error is being encountered as wrong answer …!!
what’s wrong in my code.?(python3)
https://www.codechef.com/viewsolution/31909113

please help…a humble request

Can anybody help me what is the wrong with the code? It is showing WA , I Passed all the test cases.
https://www.codechef.com/viewsolution/31909967

1 Like

Can anybody help me what is the wrong with the code? It is showing WA , I Passed all the test cases.
https://www.codechef.com/viewsolution/31913648

Your code gives NO for the below test cases.
1
2
1 0
But it should output YES.

@saurabh9997

Here is my approach.
Link: https://www.codechef.com/viewsolution/31084511

I stored the input in an array v then I checked the index of v for which value is 1 and stored it in another array named index. Then I just checked the difference between every consecutive element of the index array to be less than 6 and when it is less than 6 then flag becomes 0 and it breaks the loop and prints NO.

On your 36th line ,
Change the loop from
this :
for ( j = 0 ; j < ( ans - 1 ) ; j++ )
to this :
for ( j = 0 ; j < ans ; j++ )

why i am getting run time error . Please help I can’t make it out

while(t–)
{
cin>>n;
int a[n],b[n];

       for( i=0;i<n;i++)
       {
           cin>>a[i];
          if(a[i]==1)
         {
           b[cone]=i ;
           cone++;
        }
       }
       for(int j=0;j<cone-1;j++)
         {
             if(b[j+1]-b[j]<6)
                 {
                     flag=1;
                     break;
                 }
          }
         if(flag==1)
         cout<<"NO\n";
         else
         cout<<"YES\n";
         
   }

Sir,
can you say me what’s wrong with my code that even though I passed all the test cases, when I am trying to submit I am getting wrong answer error.
h

can someone please guide me what is wrong with this code as i am getting all the custom cases right

/* 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 boolean covid_19(int[] arr)
{
    int size = arr.length;
    int rt=0,wr=0;
    for(int i : arr)
    {   
        if(i==0)
            ++rt;
        if(i==1)
        {
            if(rt>=5){
                wr=1;
                rt=0;
                }
            else{
                wr=0;
                rt=0;
            }
        }
    }
    if(rt==arr.length)
        return true;
    if(wr==0)
        return false;
    else
        return true;
}
public static void main (String[] args) throws java.lang.Exception
{
	// your code goes here
	
	Scanner sc = new Scanner(System.in);
   int[] adi = new int[100];
   int t = sc.nextInt();
    while(t>0){
        
        int n = sc.nextInt();
        for(int i=0;i<n;i++)
            adi[i]=sc.nextInt();
        if(covid_19(adi))
            System.out.println("YES");
        else
            System.out.println("NO");
        t--;
        }               
}

}

@who_jeetu you pointed it out exactly! I was having the same problem and I was also lost in it and couldn’t debug it!
Thanks man! :smile: Much appreciated

Can someone please look into below solution that I uploaded in C#
https://www.codechef.com/viewsolution/32637601

Here I have used an regex approach to search for a pattern ‘100000’. It worked for almost all the test-cases I tried. Also it would give O(N) time complexity for each test case.

Please let me know why it says wrong answer or give me some test-case that it would fail for.It would be really motivating as this was my first attempt at CodeChef.

Can someone please explain. why it is not working. I tested with the provided input as well as my own test cases. and this doesn’t seem to be breaking at any point.
Please tell me the test case this code won’t be able to give the correct answer.
https://www.codechef.com/viewsolution/37948632

#include
using namespace std;

int main() {
int T;
cin>>T;
int ans[T];
for(int j=0; j<T; j++) // for test cases
{
int N,i;
cin>>N;
int arr[N];
for(i=0;i<N;i++)
{
cin>>arr[i];
}
i=0;
while(arr[i] != 1)
{
i++;
}
int a=i;
for(i=a+1;i<N;i++)
{
if(arr[i]==1)
{
if(i-a<6)
{
a=0;
break;
}
else
{
a = i;
}
}
}
if(a==0)
{
ans[j]=0;
}
else
ans[j]=1;
}

for(int j=0;j<T;j++)
{
if(ans[j]==1)
{
cout<<“YES\n”;
}
else
{
cout<<“NO\n”;
}
}

return 0;

}
It’s showing wrong solution even though test cases are running perfectly

Why is this giving WA?
`#include <bits/stdc++.h>
#define fast1 ios_base::sync_with_stdio(false)
#define fast2 cin.tie(NULL)
using namespace std;
/*int GCD(int a,int b)
{
if(a==0)
return b;
if(b==0)
return a;
if(a>b)
return GCD(b,a%b);
else
return GCD(a,b%a);

}*/

int main()
{
fast1;fast2;
// your code goes here
//ios_base::sync_with_stdio(false)
//cin.tie(NULL);
int t;
cin>>t;
while(t–)
{
int n;
cin>>n;
vector v(n);
for(int i=0;i<n;i++)
cin>>v[i];
int flag=1;
// for(auto it=v.begin();it<v.end()-1;it++)
// {
// if(*it==1)
// {
// auto it2=find(it+1,v.end(),1);
// if(abs(distance(it2,it))<6)
// {
// flag=0;
// break;
// }
// }
// }

        int c=0;
        for(int i=0;i<n;i++)
        {
              if(v[i]==0)
                    c++;
              else
              {
                  if(c<5)
                  {
                        flag=0;
                        break;
                  }
                    c=0;
              }
                   
        }
        

if(flag)
    cout<<"YES\n";
else
    cout<<"NO\n";
}

}
`