596A - Wilbur and Swimming Pool - CodeForces Solution


geometry implementation *1100

Please click on ads to support us..

Python Code:

n = int(input())
v = []
a = 0

for i in range(n):
    v.append(list(map(int, input().split())))

if n <= 1:
    print(-1)
else:
    if n == 2:
        if v[0][0] == v[1][0] or v[0][1] == v[1][1]:
            print(-1)
        else:
            a = abs(v[0][0] - v[1][0])*abs(v[0][1] - v[1][1])
            print(a)
    elif n == 3:
        if v[0][0] != v[1][0] and v[0][1] != v[1][1]:
                        a = abs(v[0][0] - v[1][0])*abs(v[0][1] - v[1][1])
            print(a)
        elif v[0][0] != v[2][0] and v[0][1] != v[2][1]:
                        a = abs(v[0][0] - v[2][0])*abs(v[0][1] - v[2][1])
            print(a)
        else:
                        a = abs(v[2][0] - v[1][0])*abs(v[2][1] - v[1][1])
            print(a)
    else:
        if v[0][0] != v[1][0] and v[0][1] != v[1][1]:
                        a = abs(v[0][0] - v[1][0])*abs(v[0][1] - v[1][1])
            print(a)
        elif v[0][0] != v[2][0] and v[0][1] != v[2][1]:
                        a = abs(v[0][0] - v[2][0])*abs(v[0][1] - v[2][1])
            print(a)
        else:
                        a = abs(v[0][0] - v[3][0])*abs(v[0][1] - v[3][1])
            print(a)

 	     			 	    		 	 		 		 	

C++ Code:

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

typedef long long LL;
typedef unsigned long long ULL;

// const int maxn = ;

int value(set<int> &s){
    return *s.begin() - *s.rbegin();
}


int main()
{

    int n;
    cin >> n;

    set<int> a;
    set<int> b;

    for (int i = 1; i <= n; i++) {
        int aa, bb;
        cin >> aa >> bb;
        a.insert(aa);
        b.insert(bb);
    }

    if (a.size() < 2 || b.size() < 2) {
        cout << -1;
    }
    else {
        cout << value(a) * value(b) << endl;
    }

    return 0;
}


Comments

Submit
0 Comments
More Questions

1478B - Nezzar and Lucky Number
228A - Is your horseshoe on the other hoof
122A - Lucky Division
1611C - Polycarp Recovers the Permutation
432A - Choosing Teams
758A - Holiday Of Equality
1650C - Weight of the System of Nested Segments
1097A - Gennady and a Card Game
248A - Cupboards
1641A - Great Sequence
1537A - Arithmetic Array
1370A - Maximum GCD
149A - Business trip
34A - Reconnaissance 2
59A - Word
462B - Appleman and Card Game
1560C - Infinity Table
1605C - Dominant Character
1399A - Remove Smallest
208A - Dubstep
1581A - CQXYM Count Permutations
337A - Puzzles
495A - Digital Counter
796A - Buying A House
67A - Partial Teacher
116A - Tram
1472B - Fair Division
1281C - Cut and Paste
141A - Amusing Joke
112A - Petya and Strings