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.
# | User | Rating |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 150 |
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.
Can anyone please provide an approach or hint on how we can solve the below problem using two pointers. Shopping Clothes
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
#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.
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
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
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.
Name |
---|