제출 #1141274

#제출 시각아이디문제언어결과실행 시간메모리
1141274LucaLucaMPort Facility (JOI17_port_facility)C++17
22 / 100
6093 ms40564 KiB
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>

using ll = long long;
#define debug(x) #x << " = " << x << '\n'

const int NMAX = 1e6;
const int mod = 1e9 + 7;

struct Container {
  int x, y;
  bool operator < (const Container &other) const {
    return x != other.x? x < other.x : y < other.y;
  };
};

Container a[NMAX + 1];

std::vector<int> g[NMAX + 1];
bool vis[NMAX + 1];
int color[NMAX + 1];
bool bad = false;

void dfs(int u) {
  vis[u] = true;
  for (const auto &v : g[u]) {
    if (!vis[v]) {
      color[v] = (color[u] ^ 1);
      dfs(v);
    } else {
      if (color[u] == color[v]) {
        bad = true;
      }
    }
  }
}

int main() {
  #ifdef LOCAL
    freopen("input.txt", "r", stdin);
  #endif
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  int n;
  std::cin >> n;

  for (int i = 1; i <= n; i++) {
    std::cin >> a[i].x >> a[i].y;
  }

  std::sort(a + 1, a + n + 1);

  for (int i = 1; i < n; i++) {
    for (int j = i + 1; j <= n; j++) {
      if (a[i].y > a[j].x && a[i].y < a[j].y) {
        g[i].push_back(j);
        g[j].push_back(i);
      }
    }
  }

  int answer = 1;

  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      color[i] = 0;
      dfs(i);
      if (bad) {
        std::cout << 0;
        return 0;
      }
      answer = (2 * answer) % mod;
    }
  }


  std::cout << answer;

  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...