updated logic of 1913B

This commit is contained in:
ShazidMahsrafi 2023-12-19 15:55:24 +06:00
parent 935786887e
commit 29fa4d39c5

View File

@ -61,54 +61,21 @@ void solve()
{ {
string s; string s;
cin>>s; cin>>s;
if(sz(s)==1) int n=sz(s);
vector<int>cnt(2,0);
for(int i=0; i<n; ++i)
cnt[s[i]-'0']++;
for(int i=0; i<n; ++i)
{ {
cout<<1<<endl; int x=(s[i]-'0')^1;
return; if(cnt[x]==0)
}
int ct0=0, ct1=0;
for(auto c:s)
{
if(c=='0')
ct0++;
else
ct1++;
}
if(ct1==ct0)
{
cout<<0<<endl;
return;
}
int ans=0,diff;
if(ct1>ct0)
{
diff=ct1-ct0;
for(int i=sz(s); i>=0; --i)
{ {
if(s[i]=='1') cout<< n-i<<endl;
{ return;
diff--;
}
if(diff==0)
break;
ans++;
} }
cnt[x]--;
} }
else cout<<0<<endl;
{
diff=ct0-ct1;
for(int i=sz(s); i>=0; --i)
{
if(s[i]=='0')
{
diff--;
}
if(diff==0)
break;
ans++;
}
}
cout<<ans<<endl;
} }
int32_t main() int32_t main()