Submission #43728

#TimeUsernameProblemLanguageResultExecution timeMemory
43728MatheusLealVPort Facility (JOI17_port_facility)C++14
22 / 100
136 ms33472 KiB
#include <bits/stdc++.h> #define N 3001 #define mod (1000000000 + 7) #define f first #define s second using namespace std; typedef pair<int, int> pii; int n, ans, block[N][N], cor[N], qtd, pot[N]; pii v[N]; bool nope = false; vector<int> grafo[N]; bool intersect(int i, int j) { if(v[j].f < v[i].f) swap(i, j); if(v[i].f <= v[j].f && v[j].s <= v[i].s) return false; if(v[i].f < v[j].f && v[j].f < v[i].s) return true; return false; } void dfs_color(int x) { for(auto v: grafo[x]) { if(cor[v] == cor[x]) { nope = true; return; } if(cor[v] != -1) continue; cor[v] = (cor[x] + 1)%2; dfs_color(v); } } int main() { ios::sync_with_stdio(false); cin.tie(0); cin>>n; for(int i = 1; i <= n; i++) cin>>v[i].f>>v[i].s; pot[0] = 1; for(int i = 1; i <= n; i++) pot[i] = (2*pot[i - 1])%mod; for(int i = 1; i <= n; i++) { for(int j = 1; j <= n; j++) { if(intersect(i, j)) { grafo[i].push_back(j); grafo[j].push_back(i); } } } memset(cor, -1, sizeof cor); for(int i = 1; i <= n; i++) { if(cor[i] == -1) { qtd ++; cor[i] = 0; dfs_color(i); } } cout<<(nope ? 0 : pot[qtd])<<"\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...