結果

問題 No.274 The Wall
ユーザー SHIJOUSHIJOU
提出日時 2020-09-12 04:16:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 373 ms / 2,000 ms
コード長 4,200 bytes
コンパイル時間 2,542 ms
コンパイル使用メモリ 219,388 KB
実行使用メモリ 192,168 KB
最終ジャッジ日時 2023-09-04 02:55:37
合計ジャッジ時間 4,934 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 132 ms
69,668 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 373 ms
192,168 KB
testcase_12 AC 34 ms
4,376 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 8 ms
4,376 KB
testcase_15 AC 19 ms
4,376 KB
testcase_16 AC 121 ms
42,192 KB
testcase_17 AC 115 ms
39,256 KB
testcase_18 AC 122 ms
41,988 KB
testcase_19 AC 36 ms
4,376 KB
testcase_20 AC 41 ms
4,376 KB
testcase_21 AC 43 ms
4,376 KB
testcase_22 AC 47 ms
4,376 KB
testcase_23 AC 47 ms
4,376 KB
testcase_24 AC 46 ms
4,376 KB
testcase_25 AC 46 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0xccccccc;
const ll LINF = 0xcccccccccccccccLL;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

struct SCC {
  struct csr {
    vector<int> start, elist;
    csr(int n, const vector<pair<int, int>> &edges)
      : start(n+1), elist(edges.size()) {
        for(pair<int, int> e:edges) {
          start[e.first+1]++;
        }
        for(int i = 1; i <= n; i++) {
          start[i] += start[i-1];
        }
        vector<int> counter = start;
        for(pair<int, int> e:edges) {
          elist[counter[e.first]++] = e.second;
        }
    }
  };
  int n;
  vector<pair<int, int>> edges;
  SCC(int n_) : n(n_) {}
  void add(int from, int to) {edges.emplace_back(from, to);}
  pair<int, vector<int>> scc_ids() {
    csr g(n, edges);
    int now_ord = 0, group_num = 0;
    vector<int> used, low(n), ord(n, -1), ids(n);
    used.reserve(n);
    auto dfs = [&](auto self, int v)->void {
      low[v] = ord[v] = now_ord++;
      used.push_back(v);
      for(int i = g.start[v]; i < g.start[v+1]; i++) {
        int to = g.elist[i];
        if(ord[to] == -1) {
          self(self, to);
          low[v] = min(low[v], low[to]);
        }
        else {
          low[v] = min(low[v], ord[to]);
        }
      }
      if(low[v] == ord[v]) {
        while(true) {
          int u = used.back();
          used.pop_back();
          ord[u] = n;
          ids[u] = group_num;
          if(u == v) break;
        }
        group_num++;
      }
    };
    for(int i = 0; i < n; i++) {
      if(ord[i] == -1) dfs(dfs, i);
    }
    for(int &x:ids) {
      x = group_num - 1 - x;
    }
    return {group_num, ids};
  }
  vector<vector<int>> scc() {
    pair<int, vector<int>> ids = scc_ids();
    int group_num = ids.first;
    vector<int> counts(group_num);
    for(int x:ids.second) counts[x]++;
    vector<vector<int>> groups(group_num);
    for(int i = 0; i < group_num; i++) {
      groups[i].reserve(counts[i]);
    }
    for(int i = 0; i < n; i++) {
      groups[ids.second[i]].push_back(i);
    }
    return groups;
  }
};

//SCC is needed

struct two_sat {
  int n;
  vector<bool> boolean_val;
  SCC scc;
  two_sat():n(0), scc(0) {}
  two_sat(int n_):n(n_), boolean_val(n_), scc(n_<<1) {}

  void add(int i, bool ii, int j, bool jj) {
    scc.add(i + (ii?0:n), j + (jj?n:0));
    scc.add(j + (jj?0:n), i + (ii?n:0));
  }
  bool satisfiable() {
    vector<int> id = scc.scc_ids().second;
    for(int i = 0; i < n; i++) {
      if(id[i] == id[i+n]) return false;
      boolean_val[i] = id[i] < id[i+n];
    }
    return true;
  }
};


#define M 4010

//head

int n, m;
set<pair<P, int>> se;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  two_sat TS(n);
  rep(i, n) {
    int l, r;
    cin >> l >> r;
    for(auto x:se) {
      int lx, rx;
      tie(lx, rx) = x.first;
      int id = x.second;
      if(lx > r) break;
      if(rx < l) continue;
      if(id < n) TS.add(i, false, id, false);
      else TS.add(i, false, id-n, true);
    }
    for(auto x:se) {
      int lx, rx;
      tie(lx, rx) = x.first;
      int id = x.second;
      if(lx > m-l-1) break;
      if(rx < m-r-1) continue;
      if(id < n) TS.add(i, true, id, false);
      else TS.add(i, true, id-n, true);
    }
    se.emplace(P(l, r), i);
    se.emplace(P(m-r-1, m-l-1), i+n);
  }
  cout << (TS.satisfiable()?"YES\n":"NO\n");
}
0