ENJJUN6 - Editorial

Problem Link
Contest Link

Author: Sweta Seth
Tester: Shekhar Shrivastava, Anjali Jha, Akash Kumar Bhagat
Editorialist: Sweta Seth

DIFFICULTY:

CAKEWALK

PROBLEM:

In the problem, it is required to find who among Polo and Zozo reaches the target with maximum coins at the end.

QUICK EXPLANATION:

Find who among Polo and Zozo drops lesser number of coins during the game.

EXPLANATION:

Note: Whichever path is followed you will get the same result.

→ Horizontal distance travelled by Polo from (1,1) to (x,y) = (x-1)
→ Vertical distance travelled by Polo from (1,1) to (x,y) = (y-1)

So, total coins dropped by Polo = (x-1)+(y-1)*2

Similarly,
→ Horizontal distance travelled by Zozo from (n,n) to (x,y) = (n-x)
→ Vertical distance travelled by Zozo from (n,n) to (x,y) = (n-y)

So, total coins dropped by Zozo = (n-x)+(n-y)*2

TIME COMPLEXITY:

O(1) i.e, constant time

SOLUTIONS:

C++
Setter’s Solution

#include <bits/stdc++.h>
using namespace std;
int main(){
 
    int t;
    cin >> t;

    while(t--){
        int n,x,y,r;
        cin >> n >> x >> y >> r;
        long long Polo = (y-1) + (x-1)*2;
        long long Zozo = (n-y) + (n-x)*2;
        // cout<< Polo << " " << Zozo <<'\n';
        if (Polo==Zozo) cout<< "Draw" << '\n';
        else if (Polo > Zozo)  cout<< "Zozo" << '\n';
        else  cout<< "Polo" << '\n';
    }
}