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;
const int nx=2e3+5, mod=1e9+7;
int n, l[nx], r[nx], res=1, cnt, c[nx], f, vs[nx];
vector<int> d[nx];
pair<int, int> v[nx];
void dfs(int u)
{
vs[u]=1;
for (auto v:d[u])
{
if (vs[v])
{
if (c[v]==c[u]) f=1;
continue;
}
c[v]=!c[u];
dfs(v);
}
}
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n;
for (int i=1; i<=n; i++) cin>>l[i]>>r[i], v[l[i]]={r[i], i}, v[r[i]]={l[i], i};
for (int i=1; i<=n; i++)
{
pair<int, int> mn={1e9, 1e9};
for (int j=l[i]+1; j<r[i]; j++) mn=min(mn, v[j]);
pair<int, int> mx={-1e9, 1e9};
for (int j=l[i]+1; j<r[i]; j++) mx=max(mx, v[j]);
if (mn.first<l[i]) d[i].push_back(mn.second), d[mn.second].push_back(i);
if (mx.first>r[i] )d[i].push_back(mx.second), d[mx.second].push_back(i);
}
for (int i=1; i<=n; i++) if (!vs[i]) dfs(i), res=(res*2)%mod;
if (f) cout<<0;
else cout<<res;
}
# | 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... |