Submission #1101348

#TimeUsernameProblemLanguageResultExecution timeMemory
1101348irmuunPort Facility (JOI17_port_facility)C++17
0 / 100
1 ms336 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define ff first #define ss second #define all(s) s.begin(),s.end() #define rall(s) s.rbegin(),s.rend() const ll mod=1e9+7; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll n; cin>>n; vector<ll>a(n+1),b(n+1); vector<vector<ll>>g(n+1); for(ll i=1;i<=n;i++){ cin>>a[i]>>b[i]; } vector<ll>c(n+1,-1); for(ll i=1;i<=n;i++){ for(ll j=i+1;j<=n;j++){ if(b[j]<a[i]||b[i]<a[j]) continue; if((a[i]<b[j]&&b[j]<b[i])||(a[j]<a[i]&&b[i]<b[j])) continue; g[i].pb(j); g[j].pb(i); } } function <void(ll)> dfs=[&](ll x){ for(ll y:g[x]){ if(c[y]==-1){ c[y]=1-c[x]; dfs(y); } } }; ll ans=1; for(ll i=1;i<=n;i++){ if(c[i]==-1){ ans=ans*2%mod; c[i]=0; dfs(i); } } for(ll i=1;i<=n;i++){ for(ll j:g[i]){ if(c[i]==c[j]){ cout<<0; return 0; } } } cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...