This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// n <= 20
#include <bits/stdc++.h>
using namespace std;
int n;
vector<pair<int,int>> t;
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin>>n;
for (int i = 0; i < n; i++){
int a,b;
cin>>a>>b;
t.push_back({a,b});
}
sort(t.begin(), t.end());
int w = 0;
if (n > 20){
cout<<w<<"\n";
return 0;
}
for (int i = 0; i < (1<<n); i++){
vector<int> st1 = {2*n+1}, st2 = {2*n+1};
bool ok = 1;
for (int j = 0; j < n; j++){
while (st1.back() < t[j].first) st1.pop_back();
while (st2.back() < t[j].first) st2.pop_back();
if ((1<<j) & i){
if (t[j].second > st1.back()) ok = 0;
st1.push_back(t[j].second);
}
else{
if (t[j].second > st2.back()) ok = 0;
st2.push_back(t[j].second);
}
}
if (ok) w++;
}
cout<<w<<"\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |