제출 #656007

#제출 시각아이디문제언어결과실행 시간메모리
656007KahouPort Facility (JOI17_port_facility)C++14
22 / 100
6058 ms41360 KiB
#include<bits/stdc++.h> using namespace std; #define F first #define S second #define endl '\n' typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int mod = 1e9 + 7; int mul(int a, int b) { return 1ll*a*b%mod; } int pw(int a, int b) { int out = 1; while (b) { if (b&1) out = mul(out, a); a = mul(a,a); b>>=1; } return out; } const int N = 1e6 + 50; int n, L[N], R[N], c[N], cnt; bool bad; vector<int> adj[N]; void dfs(int u) { for (int v:adj[u]) { if (!c[v]) { c[v] = 3-c[u]; dfs(v); } else if (c[v] == c[u]) { bad = 1; } } } void solve() { cin >> n; for (int i = 1; i <= n; i++) { cin >> L[i] >> R[i]; } for (int u = 1; u <= n; u++) { for (int v = 1; v <= n; v++) { if (L[u] < L[v] && L[v] < R[u] && R[u] < R[v]) { adj[u].push_back(v), adj[v].push_back(u); } } } for (int u = 1; u <= n; u++) { if (!c[u]) { c[u] = 1; cnt++; dfs(u); } } cout << (bad? 0: pw(2, cnt)) << endl; } int main() { solve(); 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...