SPLITPAIR - Editorial

coutEven>=2 || countOdd>=2. this will work

Even this would not work I had done the same thing in the contest and got WA.

1 Like

but 14 has 4 which is the last digit

Exactly.

you cannot go backwards while splitting numbers,i.e you can only append numbers from the front or skip them.for example 552,you cannot make 25,5 . thats what he meant to say i guess.he should have written all instead of sum

This question needed some more examples so that it would be more clear according to the question we just had to count the number of odds and evens in the number and if either of those is 2 then simply return yes else no. i did this question in log(n/2) time and still it failed some testcases

its not working bcz of first condition. if n=112 you cannot split which holds the given condition. possible splits (1,12) (12,1) (11,2)

“You are given a positive integer N. You have to split each digit of N into either of two non-empty subsequences A or B.”

You need to find subsequences 303 is not a subsequence of 333750

I used the same logic but it failed. Actually, the no. of odd/even digits can be more than two and still the sum will be even. But also in that case,(>=2 instead of ==2), only one test case passed.

Fails for test case 181.

Brainstorming for hours what could go wrong and then this silly editorial!
Quite frustrating.

Here is my code below

#include <iostream>
using namespace std;

int main() {
	int t;
	cin>>t;
	while(t--) {
	    long long int n;
	    int ecount=0, ocount=0;
	    cin>>n;
	    while(n!=0) {
	        int t=n%10;
	        if(t%2==0) ecount++;
	        else ocount++;
	        n/=10;
	    }
	    if(ecount>=2 || ocount>=2) cout<<"YES"<<endl;
	    else cout<<"NO"<<endl;
	}
	return 0;
}

basically what I did is just counted no of even and odd digit. if No of odd digit and No of even digit are greater than 2 I can make an even no.
But I can’t get an AC for this solution. Can you please help me through? I can’t get on which case my code broke!

this questin is wrong definitely/
author didnt frame this question correctly

3 Likes

try 221 as n it fails. possible subsequences are-
(22,1) → (even, odd)
(2,21) → (even, odd)
in your code you are checking parity of each digit hence considering first two digits 221 but failing to include last digit 1 which fails the case

For the case where 0 is not the last digit (i.e (1, 4)), the value of F(X, Y)%2 is not zero, so this case is not the ideal case that satisfies the required condition, but there were other possible methods to split the array such that the condition is satisfied. Since we were asked to tell whether it is possible to satisfy that condition through, even if one of the method satisfies, the answer is yes.


// Online C compiler to run C program online
#include <stdio.h>

int main() {
    // Write C code here
   int t;
   scanf("%d",&t);
   while(t--)
    {
        long long int n;
        scanf("%lld",&n);
        long long int count=0;
        while(n!=0)
            {
                n/=10;
                count++;
            }
        long long int rem=0;
        rem=n%10;
       
        if(rem%2==0)
                    {
                       for(long long int i=0;i<count;++i)
                        {
                           long long int rem1=0;
                            if(i=count-1)
                            {
                                printf("No\n");
                                break;
                            }
                            
                            n/=10;
                            rem1=n%10;
                            if(rem1%2==0)
                                {
                                    printf("Yes\n");
                                    break;
                                }
                            else if(rem1%2!=0)
                                {
                                   continue;
                                }
                        }
                    }
                else if(rem%2!=0)
                    {
                        for(long long int i=0;i<count;++i)
                        {
                            long long int rem1=0;
                            if(i=count-1)
                            {
                                printf("No\n");
                                break;
                            }
                         
                            n/=10;
                            rem1=n%10;
                            if(rem1%2!=0)
                                {
                                    printf("Yes\n");
                                    break;
                                }
                            else if(rem1%2==0)
                                {
                                   continue;
                                }
                        }
                    }
          
        
    }
    
    return 0;
}

Here is a simple logic i thought should have worked. Works fine in most cases, the only problem is with output.
for example, I take 2 test cases:
66
66
Here both the testcases are same. On running, It gives ‘yes’ for first one and ‘no’ for second one.
Please help me to know where i have forgot to initialize to zero or if there is any error in the program.

Hey, if the number of odd digits or even digits are greater than 2, there is no guaranty that we can split the number to satisfy the desired condition.
As the last digit will always be present at the end on the number that is is assigned to, we will have to pick another digit to be the last digit of the other number, then only we will be able to make the party of the sum of number even, and thus satisfy the condition.

take this hint that even if odd count > 2. It can result in odd sum when the count is odd!
All the Best

Exactly what I thought too. I was like “Wow, simple. At least 2 odd or at least 2 even numbers and we will have an answer”. And I submitted and got wrong answer. Does nobody verify the questions to check if the question is clear and unambiguous before deciding to put it in a contest ? This is annoying.

Hey @bhatiavikas :smiling_face: ,
Your logic is wrong as we have to have last digit in end because we only push to front or we can skip.