제출 #127162

#제출 시각아이디문제언어결과실행 시간메모리
127162UtahaPort Facility (JOI17_port_facility)C++14
22 / 100
6080 ms24696 KiB
/*input 5 1 4 2 10 6 9 7 8 3 5 */ #include <bits/stdc++.h> #pragma GCC optimize("unroll-loops,no-stack-protector") using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef pair<ld,ld> pdd; #define IOS ios_base::sync_with_stdio(0); cin.tie(0) #define ALL(a) a.begin(),a.end() #define SZ(a) ((int)a.size()) #define F first #define S second #define REP(i,n) for(int i=0;i<((int)n);i++) #define pb emplace_back #define MP(a,b) make_pair(a,b) #define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end())))) #define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin()) template<typename T1,typename T2> ostream& operator<<(ostream& out,pair<T1,T2> P){ out<<'('<<P.F<<','<<P.S<<')'; return out; } //}}} const ll maxn=300005; const ll maxlg=__lg(maxn)+2; const ll INF64=8000000000000000000LL; const int INF=0x3f3f3f3f; const ll MOD=ll(1e9+7); const ld PI=acos(-1); const ld eps=1e-9; //const ll p=880301; //const ll P=31; ll mypow(ll a,ll b){ ll res=1LL; while(b){ if(b&1) res=res*a%MOD; a=a*a%MOD; b>>=1; } return res; } vector<int> edge[maxn]; bool tg[maxn]; bool vis[maxn]; int a[maxn],b[maxn]; void dfs(int u){ vis[u]=1; for(int v:edge[u]){ if(!vis[v]){ tg[v]=!tg[u]; dfs(v); } else{ if(tg[u]==tg[v]){ cout<<"0\n"; exit(0); } } } } int main(){ IOS; int n; cin>>n; REP(i,n) cin>>a[i]>>b[i]; REP(i,n) for(int j=0;j<n;j++) if(a[i]<a[j]){ if(a[j]<b[i]&&b[i]<b[j]){ edge[i].pb(j); edge[j].pb(i); } } int cnt=0; REP(i,n) if(!vis[i]) dfs(i),cnt++; cout<<mypow(2,cnt)<<'\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...