# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
62661 | gusfring | Port Facility (JOI17_port_facility) | C++14 | 41 ms | 1280 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;
typedef long long LL;
typedef pair<int, int> II;
const int MAXN = 2000 + 10;
const int MOD = (int) 1e9 + 7;
int n, a[MAXN], b[MAXN], c[MAXN];
bool ok;
void DFS(int u){
for(int v=1; v<=n; ++v){
bool check1 = a[u] < a[v] && a[v] < b[u] && b[u] < b[v];
bool check2 = a[v] < a[u] && a[u] < b[v] && b[v] < b[u];
if(check1 || check2){
if(c[v] == -1){
c[v] = c[u] ^ 1;
DFS(v);
}
else{
if(c[v] == c[u]) ok = false;
}
}
}
}
int main(){
scanf("%d", &n);
for(int i=1; i<=n; ++i) scanf("%d%d", &a[i], &b[i]);
int ans = 1; ok = true;
for(int i = 1; i <= n; ++i) c[i] = -1;
for(int i = 1; i <= n; ++i)
if(c[i] == -1){
c[i] = 0; DFS(i);
ans = (ans * 2) % MOD;
}
if(ok == false) puts("0");
else 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... |