I am doing the codechef June Long Challenge. The question is : https://www.codechef.com/JUNE21C/problems/DAREA I am getting right answers for the example test cases but wrong when I submit them. I don't know what I am doing wrong. Any suggestion or hint for the corner cases that I am missing would be of great help.
#include <iostream>
#include<climits>
#include<unordered_map>
#include<cmath>
#include<utility>
#include<vector>
typedef long long int ll;
using namespace std;
struct Point {
ll x;
ll y;
};
int main() {
ll t;
cin >> t;
while (t--) {
ll n;
cin >> n;
vector<Point> arr;
for (ll i = 0;i < n;i++) {
Point p;
cin >> p.x >> p.y;
arr.push_back(p);
}
if (n == 1 || n % 2 == 0) cout << 0 << endl;
else {
unordered_map<ll, pair<Point, Point>> mp2;
for (ll i = 0;i < n;i++) {
if (mp2.find(arr[i].y) == mp2.end()) {
Point p2{};
mp2[arr[i].y] = { arr[i],p2 };
}
else {
pair<Point, Point> p = mp2[arr[i].y];
Point pt = p.first;
mp2[arr[i].y] = { pt, arr[i] };
}
}
Point odd{};
for (auto i : mp2) {
ll key = i.first;
pair<Point, Point> p = i.second;
Point p2 = p.second;
if (p2.x == 0 && p2.y == 0) {
odd = p.first;
mp2.erase(key);
break;
}
}
vector<pair<Point, Point>> v;
for (auto i : mp2) {
pair<Point, Point> pt = i.second;
v.push_back(pt);
}
ll area{LLONG_MAX };
for (auto i : v) {
Point pt1 = i.first;
Point pt2 = i.second;
ll a = abs(pt2.x - pt1.x) * abs(pt1.y - odd.y);
area = min(area, a);
}
cout << area << endl;
}
}
return 0;
}
Aucun commentaire:
Enregistrer un commentaire