Submission #44587

#TimeUsernameProblemLanguageResultExecution timeMemory
44587ffreshPort Facility (JOI17_port_facility)C++17
22 / 100
6090 ms5112 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const int N = 1e6+15,mod = 1e9+7; int L[N],R[N]; int par[N],enemy[N]; int find(int a){ if(a==-1)return -1; if(a==par[a])return a; return par[a]= find(par[a]); } void make_enemy(int a,int b){ a = find(a),b = find(b); int u = find(enemy[a]), v = find(enemy[b]); if(a==b || (u!=-1 && u==v)){ printf("0\n"); exit(0); } if(v!=-1)par[v]= a; if(u!=-1)par[u]= b; enemy[a]= b; enemy[b]= a; } int check(int a,int b){ int x = (L[a]<R[b] && R[b]<R[a]); int y= (L[a]<L[b] && L[b]<R[a]); if( (x+y)%2==1)return 1; return 0; } int main(){ //freopen("input.txt","r",stdin); int n; cin>>n; vector<pair<int,int> >v; for(int i=1;i<=n;++i){ scanf("%d%d",&L[i],&R[i]); v.push_back(make_pair(L[i],i)); } sort(v.begin(),v.end()); for(int i=1;i<=n;++i)par[i]= i,enemy[i]= -1; for(int i=1;i<=n;++i) for(int j=i+1;j<=n;++j){ if(check(i,j)) make_enemy(i,j); } long long ret= 1; for(int i=1;i<=n;++i){ if(find(i)==i&& find(enemy[i])<i){ ret= (ret*2)%mod; } } cout<<ret<<endl; return 0; }

Compilation message (stderr)

port_facility.cpp: In function 'int main()':
port_facility.cpp:48:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&L[i],&R[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...