(ou7MPA - Online C++0x Compiler & Debugging Tool - Ideone.com).
this is the link to my code can someone please look at it as i am not able to find any wrong answer aq to my input.
In line 54, u should push cnt0 if cnt0>0
try to debug then.
1
9 2
001000100
Is the answer 4 for that test case?
No, its 3.
Weak test cases again then. My AC solution outputs: 4.
please can someone help me in off bulb problem i have tried all test cases which come to my mind please help
Here is my code
#include<bits/stdc++.h>
using namespace std;
//#define ll long long
#define F first
#define S second
#define N1 100005
#define N2 200005
#define endl “\n”
#define mod 1000000007
#define vll vector
#define pb push_back
#define vi vector
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
typedef long long ll;
int main()
{
fastio;
ll t;
cin>>t;
while(t–)
{
ll n,i,j,f=1,k,o=0,s=0;
cin>>n>>k;
string a;
cin>>a;
vectorv;
vectorstart(n),end(n);
vectorg(n);
ll x1=0,x2=0;
for(i=0;i<n;i++)
{
if(a[i]==‘0’)
{
x1++;
g[i]=1;
}
else
break;
}
for(j=n-1;j>=0;j–)
{
if(a[j]==‘0’&&g[j]==0)
{
x2++;
g[j]=1;
}
else
break;
}
ll ele=x1+x2;
for(i=0;i<n;i++)
{
if(a[i]==‘0’)
s++;
if(g[i]==1)
continue;
if(a[i]==‘0’)
{o++;}
else
{
if(o>0)
v.pb(o);
o=0;
}
}
//cout<<x1<<" “<<x2<<” “;
//sort(v.begin(),v.end());
if(x1>0&&x2>0)
{
v.pb(ele);
sort(v.rbegin(),v.rend());
//for(ll x : v)
//cout<<x<<” ";
ll count=0;
for(i=0;i<v.size();i++)
{
if(v[i]==ele)
count++;
}
for(i=0;i<v.size();i++)
{
if(k>=2)
{
s=s-v[i];
k=k-2;
if(v[i]==ele)
{
count--;
}
}
}
if(k>=1&&count>0)
{
if(x1>=x2)
{
s=s-x1;
}
else
{
s=s-x2;
}
}
}
else if(x1>0&&x2==0)
{
v.pb(x1);
sort(v.rbegin(),v.rend());
int f1=1;
//cout<<s<<" ";
ll count=0;
for(i=0;i<v.size();i++)
{
if(v[i]==x1)
count++;
}
for(i=0;i<v.size();i++)
{
if(k>=1&&v[i]==x1&&f1==1)
{
k=k-1;
count--;
s=s-v[i];
f1=0;
}
else if(k>=2)
{
k=k-2;
s=s-v[i];
// cout<<s<<" ";
}
// cout<<s<<" "<<k<<" ";
}
// cout<<s<<" ";
}
else if(x1==0&&x2>0)
{
v.pb(x2);
sort(v.rbegin(),v.rend());
int f1=1;
ll count=0;
for(i=0;i<v.size();i++)
{
if(v[i]==x2)
count++;
}
for(i=0;i<v.size();i++)
{
if(k>=1&&v[i]==x2&&f1==1)
{
k=k-1;
count--;
s=s-v[i];
f1=0;
}
else if(k>=2)
{
k=k-2;
s=s-v[i];
}
}
}
else
{
sort(v.rbegin(),v.rend());
for(i=0;i<v.size();i++)
{
if(k>=2)
{
s=s-v[i];
k=k-2;
}
}
}
cout<<s<<"\n";
}
}
no man should be 3
but it should be 3
codechef standards are deteriorating day by day. many like me would have wasted more then a hour on this question whose tastecase are so weak.
this condition can be handled ny the code in the later section.
how is it 3 ?
first we will remove first 2 bulb by cutting 2nd wire and with second last wire we will discoonect the last 2 bulb.
yes that give 10001. Then in order to disconnect every 0, you need 4 operations, no ?
I meant from this point 10001 you need to disconnect 4 times.
thanks
bro can u please clarify ur question.
The original string was 00000000 after performing 2 cuts 00/00000/00 we get this string. Then in the middle string we make any of them to be 1. Now our string becomes 00/11111/00, after this we start disconnecting our not satisfying 1’s those at index 4, 5, 6 considering it to 1 based indexing. so in order to disconnect 3 ones we need to disconnect 4 wires.
Is it like we are removing bulbs ? Not wires ? In disconnecting operation .
i agree