Help needed in a very simple problem

Got TLE’d 6 times in a very simple problem , tried 2-3 different approaches . Can anyone help me to understand what costed me TLE’s
Link to my 6 codes

link to the question

Thanks in Advance for the help.You may help in 1 code also.

Same happened with me also

i just hack one thing to avoid tle.

Summary
ll n;
void test_cases()
{
    cin >> n;
    int c = 0;
    while(n != 0){
        int x = n%10;
        if(x%2 == 0){
            c++;
            break;
        }
        n /= 10;
    }
    if(c == 1){
        cout << 1 << "\n";
    }else{
        cout << 0 << "\n";
    }
}

i did this because in questions it written that"If any of the permutations is divisible by 2 then print 1 else print 0."

2 Likes

I don’t know why the time limit was so strict. Just print using printf and not cout. This costed me 4 TLEs

My submission, incase if it helps
void solve(){
       //input
     ll n;
      cin>>n;
      ll flag=0;
      while(n>0){
		  ll x=n%10;
		  if(x%2==0){
			  flag=1;
			  break;
		  }
		  n/=10;
	  }
	  printf("%lld\n",flag);
}
2 Likes
int solve(){
    string n;cin>>n;
    for(ll i=0;i<n.length();i++){
        int val=n[i]-'0';
        if(val%2==0)
            return 1;
    }
    return 0;
}

This should work?
I can’t submit it for some reason :sweat:

1 Like

As unfortunate as it may sound, the problem with your code was that you were flushing the output, using endl, which you didn’t change in any of your 6 solutions.

3 Likes

All your codes are correct the problem is that endl is too slow, just change it to ‘\n’ or use this macro

#define endl '\n'

in case you can’t change your habit of using endl.

3 Likes

Hello guys,
Editorial for the problem is published.

https://discuss.codechef.com/t/itguy03-editorial/83217

Thanks and Regards

1 Like

Perfectly Identified :slight_smile:

Excellent hack :grinning:

2 Likes

Nope, idts you have this macro any where in your code

3 Likes

Okkk , Thanks , will keep that in mind

2 Likes

Thanks mann, will remember this

1 Like

Yes, right. I had it before, maybe deleted it somehow. Thanks btw :slightly_smiling_face:

1 Like

It shouldn’t be the case because I was using fast input output which is faster than printf, But thanks.

#include <bits/stdc++.h>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T;
    cin>>T;
    while(T--){
        int n;
        cin>>n;
        bool flag=0;
        while(n!=0){
            if((n%10)%2==0){
                flag=1;
                break;
            }
            n/=10;
        }
        cout<<flag<<"\n";
    }
}

Using fast I/O worked.

Okkk , I got the mistake , Thanks.