1737C - Ela and Crickets - CodeForces Solution


constructive algorithms games implementation math *1500

Please click on ads to support us..

Python Code:

for _ in range(int(input())):
    n=int(input())
    a1,b1,a2,b2,a3,b3=map(int,input().split())
    x=sorted([a1,a2,a3])
    y=sorted([b1,b2,b3])
    x1,y1=map(int,input().split())
    if ({x[1],y[1]} <= {1,n}):
        print(["No","Yes"][(x1-x[1])==0 or (y1-y[1])==0])
    else :
        print(["No","Yes"][(x1+x[1])%2==0 or (y1+y[1])%2==0])

C++ Code:

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

int main ()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int qq;
    cin>>qq;
    while (qq--) {
        int n,ans=-1;
        cin>>n;
        pair<int,int>c[3];
        for (int i=0;i<3;i++) {
            cin>>c[i].first>>c[i].second;
        }
        pair<int,int>m,v,g;
        cin>>g.first>>g.second;
        if (c[0].first==c[1].first) {
            m.first=c[2].first;
            v.first=c[0].first;
        }
        else if (c[0].first==c[2].first) {
            m.first=c[1].first;
            v.first=c[0].first;
        }
        else {
            m.first=c[0].first;
            v.first=c[1].first;
        }
        if (c[0].second==c[1].second) {
            m.second=c[2].second;
            v.second=c[0].second;
        }
        else if (c[0].second==c[2].second) {
            m.second=c[1].second;
            v.second=c[0].second;
        }
        else {
            m.second=c[0].second;
            v.second=c[1].second;
        } //what
        if (((v.first==1)||(v.first==n))&&((v.second==1)||(v.second==n))) {
            if (((m.first-v.first==1)||(m.first-v.first==-1))&&((m.second-v.second==1)||(m.second-v.second==-1))) {
                if((v.first==g.first)||(v.second==g.second)){
                    ans=1;
                }
                else {
                    ans=0;
                }
            }
        }
        if (ans==-1) {
            if (!((g.first-m.first)%2)&&!((g.second-m.second)%2)) {
                ans=0;
            }
            else {
                ans=1;
            }
        }
        cout<<(ans?"YES\n":"NO\n");
    }
    return 0;
}


Comments

Submit
0 Comments
More Questions

908D - New Year and Arbitrary Arrangement
199A - Hexadecimal's theorem
519C - A and B and Team Training
631A - Interview
961B - Lecture Sleep
522A - Reposts
1166D - Cute Sequences
1176A - Divide it
1527A - And Then There Were K
1618E - Singers' Tour
1560B - Who's Opposite
182B - Vasya's Calendar
934A - A Compatible Pair
1618F - Reverse
1684C - Column Swapping
57C - Array
1713D - Tournament Countdown
33A - What is for dinner
810A - Straight A
1433C - Dominant Piranha
633A - Ebony and Ivory
1196A - Three Piles of Candies
299A - Ksusha and Array
448B - Suffix Structures
1092B - Teams Forming
1166C - A Tale of Two Lands
544B - Sea and Islands
152B - Steps
1174D - Ehab and the Expected XOR Problem
1511A - Review Site