# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
69133 | Inovak | Port Facility (JOI17_port_facility) | C++14 | 3 ms | 376 KiB |
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 <bits/stdc++.h>
#define fr first
#define sc second
#define pb push_back
#define mk make_pair
#define ll long long
#define OK puts("OK");
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()
using namespace std;
const int N = 2e6+10;
const int mod = 1e9+7;
int n;
pair <int, int> p[N];
stack <int> a, b;
ll ans = 1;
bool go (stack <int> a, stack <int> b, int k) {
for(int i = k; i <= n; i++) {
while(a.top() < p[i].fr) a.pop();
while(b.top() < p[i].fr) b.pop();
if(a.top() < b.top()) {
if(a.top() > p[i].sc) a.push(p[i].sc);
else if(b.top() > p[i].sc) b.push(p[i].sc);
else return 0;
}
else {
if(b.top() > p[i].sc) b.push(p[i].sc);
else if(a.top() > p[i].sc) a.push(p[i].sc);
else return 0;
}
}
return 1;
}
int main() {
scanf("%d", &n);
for(int i = 1; i <= n; i++) {
scanf("%d%d", &p[i].fr, &p[i].sc);
}
a.push(mod);
b.push(mod);
sort(p + 1, p + n + 1);
for(int i = 1; i <= n; i++) {
while(a.top() < p[i].fr) a.pop();
while(b.top() < p[i].fr) b.pop();
ll y = 0;
if(a.top() > p[i].sc) {
a.push(p[i].sc);
if(go(a, b, i + 1))
y += 1;
a.pop();
}
if(b.top() > p[i].sc) {
b.push(p[i].sc);
if(go(a, b, i + 1))
y += 2;
b.pop();
}
if(y == 3) {
ans = ans * 2ll % mod;
if(a.top() < b.top()) a.push(p[i].sc);
else b.push(p[i].sc);
}
else if(y) {
if(y == 1) a.push(p[i].sc);
else b.push(p[i].sc);
}
else {
puts("0");
return 0;
}
}
cout << ans << endl;
}
Compilation message (stderr)
# | 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... |