Submission #471447

#TimeUsernameProblemLanguageResultExecution timeMemory
471447RainbowbunnyPort Facility (JOI17_port_facility)C++17
22 / 100
39 ms16564 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 2005; const int mod = 1e9 + 7; int n, ans = 1; int c[MAXN]; int A[2 * MAXN], B[2 * MAXN]; vector <int> Adj[MAXN]; void DFS(int node, int color) { c[node] = color; for(auto x : Adj[node]) { if(!c[x]) { DFS(x, 3 - color); } else if(c[x] == c[node]) { cout << 0 << '\n'; exit(0); } } } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; if(n > 2000) { return 0; } for(int i = 1; i <= n; i++) { cin >> A[i] >> B[i]; } for(int i = 1; i <= n; i++) { for(int j = i + 1; j <= n; j++) { if(A[i] < A[j] and B[i] < B[j] and B[i] > A[j]) { Adj[i].push_back(j); Adj[j].push_back(i); } else if(A[i] > A[j] and B[i] > B[j] and B[j] > A[i]) { Adj[i].push_back(j); Adj[j].push_back(i); } } } for(int i = 1; i <= n; i++) { if(!c[i]) { DFS(i, 1); ans = ans * 2 % mod; } } cout << ans << '\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...