Problem: Billboard.
4th test case doesn’t pass, i have checked other solutions and i realized other people have that issue too. couldn’t figure out why.
after removing a condition in intersection function (which is necessary in my opinion, i added on the code block where i removed) test case 4 passes but others don’t , when i add it only 4th test case doesn’t pass.
My Work
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <stack>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <set>
#include <numeric>
#include <bitset>
#include <climits>
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define ll long long
//#define MOD 1000000007
using namespace std;
void setIO(string name = "") { // name is nonempty for USACO file I/O
ios_base::sync_with_stdio(0); cin.tie(0); // see Fast Input & Output
if(name.length()){
freopen((name+".in").c_str(), "r", stdin); // see Input & Output
freopen((name+".out").c_str(), "w", stdout);
}
}
struct Rec{
int x1,x2,y1,y2;
int area()
{
return (x2-x1)*(y2-y1);
}
};
int intersect(struct Rec f,struct Rec s)
{
int xinters = max(0,min(f.x2,s.x2)-max(f.x1,s.x1));
int yinters = max(0,min(f.y2,s.y2)-max(f.y1,s.y1));
if ((yinters == f.y2-f.y1) || (xinters == f.x2-f.x1)) return xinters*yinters; // after deleting xinters condition 4th testcase passes but others dont. after insterting condition only 4th testcase doesnt pass.
else return 0;
}
void solve()
{
struct Rec arr[2];
forn(i,2)
{
cin >> arr[i].x1 >> arr[i].y1 >> arr[i].x2 >> arr[i].y2;
}
cout << arr[0].area()-intersect(arr[0],arr[1]) << endl;
}
int main()
{
setIO("billboard");
solve();
}