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 jizz ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pb push_back
#define MP make_pair
#define F first
#define S second
#define MEM(i,j) memset(i,j,sizeof i)
#define ALL(v) v.begin(),v.end()
#define ET cout << "\n"
#define DB(a,s,e) {for(int i=s;i<e;++i) cout << a[i] << " ";ET;}
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD=1e9+7;
vector<int> G[1000005];
map<int,int> mp;
pii seg[1000005];
int color[1000005];
bool dfs(int u,int c)
{
color[u]=c;
for(int i:G[u])
if(!~color[i]&&!dfs(i,c^1))
return 0;
else if(color[i]==color[u])
return 0;
return 1;
}
int main()
{jizz
int n,cnt=0,flag=1,ans=1;
cin >> n;
for(int i=0;i<n;++i)
cin >> seg[i].F >> seg[i].S;
sort(seg,seg+n),MEM(color,-1);
for(int i=0;i<n&&flag;++i)
{
int w[2]={},yes=0;
for(int j=0;j<i;++j)
if(seg[j].S>seg[i].F&&seg[i].S>seg[j].S)
if(~color[j])
w[color[j]]=1;
else yes=1;
if(w[0]&&w[1]) flag=0;
else if(w[0]||w[1])
{
color[i]=w[0]?1:0;
for(int j=0;j<i;++j)
if(seg[j].S>seg[i].F&&seg[i].S>seg[j].S)
if(!~color[j])
color[j]=color[i]^1;
}
else if(yes)
{
ans=ans*2%MOD;
color[i]=0;
for(int j=0;j<i;++j)
if(seg[j].S>seg[i].F&&seg[i].S>seg[j].S)
color[j]=1;
}
}
if(flag)
for(int i=0;i<n;++i)
if(!~color[i])
ans=ans*2%MOD;
if(flag) cout << ans << "\n";
else cout << "0\n";
}
Compilation message (stderr)
port_facility.cpp: In function 'int main()':
port_facility.cpp:44:6: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
if(seg[j].S>seg[i].F&&seg[i].S>seg[j].S)
^
port_facility.cpp:35:8: warning: unused variable 'cnt' [-Wunused-variable]
int n,cnt=0,flag=1,ans=1;
^~~
# | 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... |