SLPCYCLE - Editorial

Please help me to find out error in my logic or tell me the failed logic.
Thanks

#include
#include
using namespace std;

int main()
{
int test;
cin >> test;
while(test–){
int d, s, count = 0;
string w;
cin >> d >> s >> w;
bool flag = false;
for(int i = 0; i < d; i++){
if(w.at(i) == ‘0’) count += 1;
if(count == s){
flag = true;
break;
}
if(count != 0 && w.at(i) == ‘1’){
s = 2 * (s - count);
count = 0;
}
}
if(flag) cout << “YES” << endl;
else cout << “NO” << endl;
}

return 0;

}

I am discussing here for the first time so idk how this work. I’d included iostream and string library above in my code

Can somebody please say me in which test cases is my code failing i have tried many test cases it showed correct but

#include
using namespace std;
int main(){
int t;
cin>>t;
while(t–){
int l,h;
cin>>l>>h;
string s;
cin>>s;
int count=0;
if(l>=h){
for(int i=0;i<l;i++){
if(s[i]==‘0’){
count++;
}
else {
if(count==h){
break;
}
if(s[0]==‘1’){
count=0;
}
else{
h=2*(h-count);
}
count=0;
}
}
}
if(count>=h){
cout<<“YES”<<endl;
}
else{
cout<<“NO”<<endl;
}
}
return 0;
}

try this test case-
1
8 3
10100100
the mistake is that u should not let h to be increased;
use h=min(h,2*(h-count))
[/quote]

use h=min(h,2*(h-count))
let’s assume h=10 and the chef sleeps for an hour then his remaining sleep hours nearly becomes double. that’s why he avoids sleeping whenever the next remaining sleep is greater than the current remaining sleep. (h<2*(h-count));

Actually now I understood my mistake , I didn’t think that doing 2*(h-x) could become greater than h at sometime.

I have solved this question with some other approach, but I am always getting wrong answer, Can anyone mention some test cases where my code is failing to give the correct answer.
My solution
Thanks in advance!

I have solved this question with similar approach but using priority queue(min heap). and it was accepted.

int l,h;

string s;

priority_queue <int, vector, greater > pq;

cin>>l>>h;

cin>>s;

int c=0;

pq.push(h);

for(int i=0;i<l;i++)

{

  if(s[i]=='0')c++;

  else{

      if(c>=pq.top())

      {

          cout<<"YES\n";

          return;

      }

      else{

          pq.push(2*(pq.top()-c));

      }

          c=0;

  }

}

if(c>=pq.top())

cout<<“YES\n”;

else

cout<<“NO\n”;

Thanks! for your reply

1 Like

Solution: 48284277 | CodeChef
I tried almost every test case, but the solution is wrong, can someone help that which test case I’m failing,
Help would be appreciated

Hello sirs… could you point out where my solution is failing…

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
int test;
cin>>test;
while (test --)
{
    int l,h;
    cin>>l>>h;
    char art[l];
    bool beg=true;
    vector<int> free_time;
    int u = 0;
    for (int i = 0; i < l; i++)
    {
        cin>>art[i];
        if (art[i]=='0')
        {
            u++;
        }
        else
        {
            if (u!=0)
            {
                free_time.push_back(u);
                
            }
            u = 0;
        }
    }
    if (u!=0)
    {
        free_time.push_back(u);        
    }
    for (int j = 0; j < free_time.size() ; j++)
    {
        if (free_time[j] > h/2)
        {
            h=2*(h - free_time[j]);
        }
        if (h==0)
        {
            beg = false;
            cout<<"YES"<<endl;
        }
    }
    if (beg==true)
    {
        cout<<"NO"<<endl;
    }
}
return 0;
}

also if you find somewhere my code can be optimised pls tell there also( I am kind a new to CP).

Can you please specify a test case where this is failing?

for _ in range(int(input())):
    n, h = map(int, input().split())
    s = input()
    ans = 'No'

    l1 = s.split('1')
    l2 = []    
    
    for each in l1:
        l2.append(len(each))

    for i in l2:
        if i < h:
            if i > 0:
                h = 2 * (h - i)

            else:
                continue
        else:
            ans = 'Yes'
            break

    print(ans)

Thanks a lot!

Same issue :confused:

my simple solutionhttps://www.codechef.com/viewsolution/48336766