# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
136657 | Alliance | Port Facility (JOI17_port_facility) | C++14 | 107 ms | 16444 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.
// In the Name of Allah
#include<bits/stdc++.h>
#define double long double
typedef long long ll;
const ll MAX_N = 2000+100;
const ll MOD = 1e9+7;
using namespace std;
vector<int> g[MAX_N];
bool mark[MAX_N];
int cl[MAX_N];
pair<int,int> lr[MAX_N];
int n,cnt;
bool intersect(int i,int j){
if (lr[i].first>lr[j].second or lr[j].first>lr[i].second)
return false;
if (lr[i].first<=lr[j].first and lr[j].second<=lr[i].second)
return false;
swap(i,j);
if (lr[i].first<=lr[j].first and lr[j].second<=lr[i].second)
return false;
return true;
}
void no(){
cout << 0;
exit(0);
}
void dfs(int v)
{
mark[v]++;
for(auto x:g[v]){
if (mark[x]){
if (cl[x]==cl[v])
no();
}
else{
cl[x] = 3-cl[v];
dfs(x);
}
}
}
int main()
{
cin >> n;
for(int i = 1;i<=n;++i)
scanf("%d%d",&lr[i].first,&lr[i].second);
if (n>2000)
exit(1);
for(int i = 1;i<=n;++i){
for(int j = 1;j<=n;++j){
if (intersect(i,j))
g[i].push_back(j);
}
}
for(int i = 1;i<=n;++i){
if (mark[i])
continue;
cnt++;
cl[i] = 1;
dfs(i);
}
ll ans = 1;
for(int i = 1;i<=cnt;++i)
ans *= 2,ans %= MOD;
cout << 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... |