제출 #832588

#제출 시각아이디문제언어결과실행 시간메모리
832588LucaIliePort Facility (JOI17_port_facility)C++17
22 / 100
6054 ms2164 KiB
#include <bits/stdc++.h> using namespace std; struct container { int l, r; bool operator < ( container c ) { return l < c.l; } }; const int MAX_N = 1e6; const int MOD = 1e9 + 7; int n; bool bipartit = true; bool vis[MAX_N], side[MAX_N]; container containers[MAX_N]; void checkBipartit( int u ) { vis[u] = true; for ( int v = 0; v < u; v++ ) { if ( !(containers[v].r > containers[u].l && containers[v].r < containers[u].r) ) continue; if ( vis[v] ) { if ( side[u] == side[v] ) bipartit = false; } else { side[v] = side[u] ^ 1; checkBipartit( v ); } } for ( int v = u + 1; v < n; v++ ) { if ( !(containers[u].r > containers[v].l && containers[u].r < containers[v].r) ) continue; if ( vis[v] ) { if ( side[u] == side[v] ) bipartit = false; } else { side[v] = side[u] ^ 1; checkBipartit( v ); } } } int main() { cin >> n; for ( int i = 0; i < n; i++ ) cin >> containers[i].l >> containers[i].r; sort( containers, containers + n ); int comp = 0; for ( int u = 0; u < n; u++ ) { if ( !vis[u] ) { side[u] = 0; checkBipartit( u ); comp++; } } if ( bipartit ) { int ans = 1; for ( int i = 0; i < comp; i++ ) ans = ans * 2 % MOD; cout << ans; } else cout << 0; 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...