This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <utility>
#include <algorithm>
#include <vector>
using namespace std;
vector<pair<int, int> > first_space;
vector<pair<int, int> > second_space;
int main()
{
int n;
cin >> n;
for (int i = 0; i < n; i++)
{
int a, b;
cin >> a >> b;
first_space.push_back(make_pair(a, b));
}
for (int i = 0; i < n; i++)
{
int a, b;
cin >> a >> b;
second_space.push_back(make_pair(a, b));
}
int numOfOverlap = 0;
bool isGap = true;
for (int i = 0; i < first_space.size(); i++)
{
int a_from = first_space[i].first;
int a_to = first_space[i].second;
int b_from = second_space[i].first;
int b_to = second_space[i].second;
if (a_from == b_from)
{
numOfOverlap++;
}
else if (a_from > b_from)
{
if (b_to < a_from) isGap = false;
else if (b_to == a_from) numOfOverlap = numOfOverlap;
else if (b_to > a_from) numOfOverlap++;
}
else if (a_from < b_from)
{
if (a_to < b_from) isGap = false;
else if (a_to == b_from) numOfOverlap = numOfOverlap;
else if (a_to > b_from) numOfOverlap++;
}
}
if (isGap == false)
cout << -1 << endl;
else
cout << numOfOverlap << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |