TWOGRS - Editorial

I think the approaches are equivalent. Yet I cannot find a test case that would fail my code.

You should first of all check, if the sum is even or not, if you don’t do that, you are bound to mess up few cases, as it was seen by so many Was during the contest :slight_smile:

The sum would be odd only in the first 4 cases (i.e. when exactly one of a or c is odd) that I reject immediately.

Can anyone pls explain the TESTER’s solution?

2 Likes

Can anyone please suggest me the mistake in my program. As, the testcases I am able to think gives the correct output, but instead it is showing wrong answer.
I will be very much thankful to the one who helps me…

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

int main(){
int t;
cin>>t;
while(t–){
ll a, b, c;
cin>>a>>b>>c;
ll sum = a1 + b2 + c*3;
if(sum%2!=0){
cout<<“NO”<<endl;
}
else if(a==0&&b==0&&c==0){
cout<<“NO”<<endl;
}
else if(c%2==0){
if(a%2!=0){
cout<<“NO”<<endl;
}else{
if(b%2!=0){
if(a<2){
cout<<“NO”<<endl;
}else{
cout<<“YES”<<endl;
}
}else{
cout<<“YES”<<endl;
}
}
}else{
if(a%2==0){
cout<<“NO”<<endl;
}else{
if(b%2==0){
if(a>=3){
cout<<“YES”<<endl;
}else{
cout<<“NO”<<endl;
}
}else{
cout<<“YES”<<endl;
}
}
}
}

return 0;

}

Also please tell me the case for this it doesn’t work correctly…

Check my editorial for this problem here :- Unofficial editorial-TWOGRS

2 Likes

can anyone please tell me what is the mistake in my code.
#include<stdio.h>
int main()
{
int t,T;
long int A,B,C;
long long int sum1,sum2;
scanf("%d",&T);
for(t=0;t<T;t++)
{
scanf("%ld %ld %ld",&A,&B,&C);
sum1=sum2=A1+B2+C3;
if(sum1%2!=0)
printf(“NO\n”);
else
{
sum1=sum1/2;
while(sum1>0)
{
if(sum1==1 && A>0)
{
sum1-=1;
A-=1;
}
else if(sum1==2 && B>0)
{
sum1-=2;
B-=1;
}
else if(sum1==3 && C>0)
{
sum1-=3;
C-=1;
}
else
{
if(A>0)
{
sum1-=1;
A-=1;
}
else if(B>0)
{
sum1-=2;
B-=1;
}
else if(C>0)
{
sum1-=3;
C-=1;
}
else
break;
}
}
sum2=sum2/2;
if(sum1==0)
{
if((1
A+2B+3C) == sum2)
printf(“YES\n”);
else
printf(“NO\n”);
}
else
printf(“NO\n”);
}
}
return 0;
}

How to reach the conclusion that 7,4,4 need to be used to lower the constraints without affecting the solution. Plz reply!!

how fix functions has been evaluated and what this function is actually doing…Can somebody please help @taran_1407

1 Like

I am also trying same approach @nihaljain , Everyting seems fine yet getting WA , can someone check and explain what I am doing wrong.My Solution

Because it’s simple bruteforce! xD

Not just that, he found out that subtracting two from any of the A, B, C does not change the answer to be printed.

can any one tell me What wrong in my approach ?

#include <bits/stdc++.h>
using namespace std;

int main() {
// your code goes here
//freopen(“input.txt”,“r”,stdin);
int t;
cin>>t;
while(t–){
int a,b,c;
cin>>a>>b>>c;
long long sum1 = 0;
long long sum2 = 0;

    if(c%2 == 1){
        sum1 += 3;
        c--;
    }
        int x = c / 2;
        sum1 += 3*x;
        sum2 += 3*x;
        if(b%2 != 0){
            if(sum1<sum2){
                sum1 += 2;
            }else
                sum2 += 2;
            b--;
        }
        x = b / 2;
        sum1 += 2*x;
        sum2 += 2*x;
        long long diff = sum1 - sum2;
        if(a >= diff){
            a = a - diff;
            if(a%2 == 0){
            cout<<"Yes"<<endl;
            }else
                cout<<"No"<<endl;
        }else{
            cout<<"No"<<endl;
        }

}
return 0;

}

Thanks!

Can someone please tell what is wrong in my code?? Thanks

#include<bits/stdc++.h>
using namespace std;

int main()
{
    int tc;
    cin>>tc;
    int a,b,c,q1,q2,q3;
    while(tc--)
    {
        cin>>a>>b>>c;
        long int sum = a + b*2 + c*3;
        if(sum%2==1)
            cout<<"NO\n";
        else
        {
            sum=sum/2;
            q3=sum/3;
            sum = sum - min(q3,c)*3;

            q2=sum/2;
            sum = sum - min(q2,b)*2;

            q1=sum/1;
            sum = sum - min(q1,a);

            if(sum>0)
                cout<<"NO\n";
            else
                cout<<"YES\n";
        }
    }
}

my approch is also similar to this.and i am getting WA.and i dont know the reason.

#include<bits/stdc++.h>
using namespace std;

#define MOD (1000000007)
//Data-type
#define ui unsigned int
#define d(str) cout<<#str<<" : “<<str<<”\n"
#define nl cout<<’\n’
#define fast ios_base::sync_with_stdio(0)
#define mem(a,b) memset(a,b,sizeof(a))
#define arr_sort(a,n) stable_sort(a,a+n)
#define _sort(a) stable_sort(a.begin(),a.end())
#define test int t=0,i=0,j=0;
cin>>t;
while(t–)
#define min(a,b) ((a)>(b)?(b):(a))

int main()
{
fast;
int a,b,c,sum;
test
{
cin>>a>>b>>c;
sum=a+2b+3c;
if(sum&1)
cout<<“NO”;
else
{
int x,k=sum;

        k/=2;
        x=k/3;
        k=k-3*min(x,c);

        x=k/2;
        k=k-2*min(x,b);

        if(k <= a)
            cout<<"YES";
        else
            cout<<"NO";
    }
    nl;
}
return 0;

}

@admin Why this solution accepted?

For case: 0 7 10
This solution provide NO But it should be YES
Given : [0 7 10] => {0, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3}
Group 1 : {2, 2, 3, 3, 3, 3, 3, 3}
Group 2: {2, 2, 2, 2, 2, 3, 3, 3, 3}

Some contestant +rated for this solution, Please check out it. Thanks.

3 Likes

@spd_25 Please check out the following test cases::

41 0 45
63 0 97
0 9 20
0 45 46

Do you need more test cases??

1 Like

How did you reach this solution !? Specifically saying from step 3 to 5.

You should provide the link of your solution or format it correctly.
Just copy and pest your code between ``` and ```

\```
Code here
\```

[Without back slash \]

Ready my editorial for detailed explanation :slight_smile: