Submission #190119

#TimeUsernameProblemLanguageResultExecution timeMemory
190119fedoseevtimofeyPort Facility (JOI17_port_facility)C++14
22 / 100
155 ms32756 KiB
#include <iostream> #include <string> #include <vector> #include <queue> #include <deque> #include <stack> #include <set> #include <map> #include <unordered_map> #include <unordered_set> #include <cstring> #include <cmath> #include <cstdlib> #include <algorithm> #include <random> #include <iomanip> #include <cassert> #include <complex> #include <functional> using namespace std; typedef long long ll; const int md = 1e9 + 7; void add(int &a, int b) { a += b; if (a >= md) a -= md; } int mul(int a, int b) { return ((ll)a * b) % md; } int power(int a, ll b) { int res = 1; while (b > 0) { if (b & 1) res = mul(res, a); a = mul(a, a); b >>= 1; } return res; } int inv(int a) { return power(a, md - 2); } const int N = 2e3 + 7; vector <int> g[N]; int col[N]; void dfs(int u) { for (auto v : g[u]) { if (col[v] == -1) { col[v] = col[u] ^ 1; dfs(v); } else if (col[v] != (col[u] ^ 1)) { cout << "0\n"; exit(0); } } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); #ifdef LOCAL freopen("input.txt", "r", stdin); #endif int n; cin >> n; vector <int> a(n), b(n); for (int i = 0; i < n; ++i) cin >> a[i] >> b[i]; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { if (a[i] < a[j] && a[j] < b[i] && b[i] < b[j]) { g[i].push_back(j); g[j].push_back(i); } else if (a[j] < a[i] && a[i] < b[j] && b[j] < b[i]) { g[i].push_back(j); g[j].push_back(i); } } } fill(col, col + n, -1); int cmp = 0; for (int i = 0; i < n; ++i) { if (col[i] == -1) { ++cmp; col[i] = 0; dfs(i); } } int ans = power(2, cmp); 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...