# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
81895 | aquablitz11 | Port Facility (JOI17_port_facility) | C++14 | 35 ms | 1328 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>
using namespace std;
using pii = pair<int, int>;
#define x first
#define y second
const int N = 2010;
const int MOD = 1e9+7;
int n, ans = 1;
pii A[N];
pii ev[N*2];
int col[N];
bool intersect(int al, int ar, int bl, int br)
{
if (bl > ar || br < al) return false;
if (bl >= al && br <= ar) return false;
if (al >= bl && ar <= br) return false;
return true;
}
void solve(int i)
{
for (int j = 0; j < n; ++j) {
if (intersect(A[i].x, A[i].y, A[j].x, A[j].y)) {
if (col[j] != 0)
continue;
col[j] = col[i] == 1 ? 2 : 1;
solve(j);
}
}
}
int main()
{
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d%d", &A[i].x, &A[i].y);
ev[A[i].x-1] = pii(i, 1);
ev[A[i].y-1] = pii(i, 2);
}
for (int i = 0; i < n && ans != 0; ++i) {
if (!col[i]) {
col[i] = 1;
solve(i);
ans = (ans*2)%MOD;
}
}
stack<int> S[2];
for (int i = 0; i < 2*n; ++i) {
int x = ev[i].x, t = ev[i].y;
int c = col[x]-1;
if (t == 1)
S[c].push(x);
else {
if (S[c].top() != x) {
ans = 0;
break;
}
S[c].pop();
}
}
printf("%d\n", ans);
return 0;
}
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... |