WHY I AM GETTING WRONG ANS FOR CHEALG

HERE IS MY CODE

#include<bits/stdc++.h>
#include
#include
using namespace std;
int main()
{
int t;
cin>>t;
while(t–){
string s;
cin>>s;
int n=s.length();
vectorv;
v.push_back(0);
int ans=0;
for(int i=1;i<n;i++)
{
if(s[i]!=s[i-1])v.push_back(i);
}
v.push_back(n-1);
for(int i=0;i<v.size();i++)cout<<v[i]<<" ";cout<<endl;
for(int i=1;i<v.size();i++)
{
int k=v[i]-v[i-1];
if(k<10)ans=ans+2;
else if(k>=10 && k<=99)ans=ans+3;
else if(k>=100 && k<=999)ans=ans+4;
else if(k==1000)ans=ans+5;
}
// cout<<n<<endl;
//cout<<ans<<endl;
if(ans<n)cout<<“YES”<<endl;
else cout<<“NO”<<endl;
}
}

Please either format your code or link to your submission - the forum software has mangled it and it won’t compile! :slight_smile:

Edit:

One immediately obvious problem - your program’s output has to match the expected output exactly, and the output from this:

for(int i=0;i<v.size();i++)cout<<v[i]<<" ";cout<<endl;

is definitely not expected.

1 Like

That is a comment…
At the time of submission

#include<bits/stdc++.h>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--){
        string s;
        cin>>s;
        int n=s.length();
        vector<int>v;
        v.push_back(0);
        int ans=0;
        for(int i=1;i<n;i++)
        {
            if(s[i]!=s[i-1])v.push_back(i);
        }
        v.push_back(n-1);
       // for(int i=0;i<v.size();i++)cout<<v[i]<<" ";cout<<endl;
        for(int i=1;i<v.size();i++)
        {
            int k=v[i]-v[i-1];
            if(k<10)ans=ans+2;
            else if(k>=10 && k<=99)ans=ans+3;
            else if(k>=100 && k<=999)ans=ans+4;
            else if(k==1000)ans=ans+5;
        }
       // cout<<n<<endl;
        //cout<<ans<<endl;
        if(ans<n)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}
  
1 Like

Hmmm … I can’t actually see anything wrong with that - can you link to the failing submission? Go to the Problem page; click “My Submissions”; click on “View” for the submission you want checked, and copy and paste the URL from your browser here.

2 Likes

Have a look at my submission for CHEALG, we’ve the same logic and implementation for it according to me.

1 Like

https://www.codechef.com/viewsolution/28556168

1 Like

That was a tough one to find - it passed 30’000 randomly-generated tests!

Consider the testcase:

1
bcdefhgaaaaaaaaaa
2 Likes

Is it the only failed test case?
or many more

It’s the only one I could find, though I think there will be another one where the input string ends in 100 consecutive a’s. This will have the same root cause as the testcase above, though.

1 Like

ohhk…thanks a lot

1 Like

change n-1 to n

1 Like

ohhk…
thanks a lot…
silly mistake:pensive::pensive:
now got AC…:smile::smile:

2 Likes