Mohsina_Shaikh's blog

By Mohsina_Shaikh, history, 16 months ago, In English

Hello, Can anyone please help me to understand why Greedy works for the above problem Painting Eggs I have read the editorial and not able to fully understand how greedy is the correct solution for the problem.

Full text and comments »

  • Vote: I like it
  • +4
  • Vote: I do not like it

By Mohsina_Shaikh, history, 23 months ago, In English

Can anyone please provide an approach or hint on how we can solve the below problem using two pointers. Shopping Clothes

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By Mohsina_Shaikh, history, 2 years ago, In English

Hello can anyone please explain how to optimize this code.Currently It is giving TLE.

#include<bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here
	int t;
	std::cin >> t;
	while(t--)
	{
       int n,m,q;
       cin>>n>>m;
       vector<pair<int,int>> haters(m,make_pair(0,0));
       int x=0,y=0;
       for(int i=0;i<m;i++){
           cin>>x>>y;
           haters[i].first=x;
           haters[i].second=y;
       }
       cin>>q;
       int k=0,li=0,ri=0;
      
       while(q--){
            
            bitset<200005> b1;
            cin>>k;
            for(int i=0;i<k;i++){
                 cin>>li>>ri;
                 //setting bits from range l to r
                 for(int j=li;j<=ri;j++){
                     b1[j]=1;
                 }
            }
             int i=0;
             for(i=0;i<m;i++){
                 //iterating over all m pairs
                 //to find if haters pair is set
                 if(b1[haters[i].first]==1 && b1[haters[i].second]==1){
                     break;
                 }
             }
             if(i==m){
                 cout<<"YES"<<"\n";
             }else{
                 cout<<"NO"<<"\n";
             }
       }
     }
	return 0;
}

Adding the Problem Link : PARTY Can anyone please help on how we can optimize this

Full text and comments »

  • Vote: I like it
  • -8
  • Vote: I do not like it

By Mohsina_Shaikh, history, 2 years ago, In English
#include <bits/stdc++.h>

using namespace std;

int main()
{
    bitset<8> bt(3);
    bt[1]|=1;
    cout<<bt[1]<<"\n";
    return 0;
}

The program throws error. Why cannot we perform bitwise operations on bitsets like this.can anyone please explain.

Full text and comments »

  • Vote: I like it
  • -3
  • Vote: I do not like it

By Mohsina_Shaikh, history, 2 years ago, In English

Can anyone please explain why my program crashes without mentioning any error If I try to create vector of size 10^9 in c++.Anyway If I decrease the size of vector let's suppose to something like 10^7 and 10^6 it works fine

Full text and comments »

  • Vote: I like it
  • -4
  • Vote: I do not like it

By Mohsina_Shaikh, history, 2 years ago, In English

Hello can anyone please help on how to solve this problem.

Adding the link for reference Bulb Switcher

Im not able to reach to a solution for this problem.Any help would be appreciated.Thanks

Full text and comments »

  • Vote: I like it
  • -18
  • Vote: I do not like it

By Mohsina_Shaikh, history, 2 years ago, In English

Is finding rightmost set bit by this approach wrong.

int ans=xorsum,int rightmost=0;
 while(ans){
            int mask=1<<i;
            if(ans&mask){
                break;
            }
            ans=ans>>1; 
            i++;
        }
   rightmost=1<<i;

My code gave WA for some test cases when I used this code snippet to find rightmost set bit.It worked when I removed this with rightmost=xorsum&(-xorsum) can anyone please why the above got snippet may not work.

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it