結果

問題 No.274 The Wall
ユーザー 👑 emthrmemthrm
提出日時 2019-09-06 03:50:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,678 bytes
コンパイル時間 1,646 ms
コンパイル使用メモリ 100,708 KB
実行使用メモリ 766,248 KB
最終ジャッジ日時 2023-09-05 09:44:20
合計ジャッジ時間 6,867 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 387 ms
224,476 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 MLE -
testcase_12 AC 12 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 6 ms
4,376 KB
testcase_15 AC 12 ms
4,376 KB
testcase_16 AC 309 ms
179,600 KB
testcase_17 AC 284 ms
170,732 KB
testcase_18 AC 320 ms
185,696 KB
testcase_19 AC 21 ms
4,376 KB
testcase_20 AC 24 ms
4,380 KB
testcase_21 AC 25 ms
4,380 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 26 ms
4,376 KB
testcase_25 AC 26 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
/*-------------------------------------------------*/
using CostType = long long;
struct Edge {
  int src, dst; CostType cost;
  Edge(int src, int dst, CostType cost = 0) : src(src), dst(dst), cost(cost) {}
  inline bool operator<(const Edge &rhs) const {
    return cost != rhs.cost ? cost < rhs.cost : dst != rhs.dst ? dst < rhs.dst : src < rhs.src;
  }
  inline bool operator<=(const Edge &rhs) const { return cost <= rhs.cost; }
  inline bool operator>(const Edge &rhs) const {
    return cost != rhs.cost ? cost > rhs.cost : dst != rhs.dst ? dst > rhs.dst : src > rhs.src;
  }
  inline bool operator>=(const Edge &rhs) const { return cost >= rhs.cost; }
};

struct SCC {
  vector<int> id;
  vector<vector<int> > vertices;
  vector<vector<Edge> > comp;

  SCC(const vector<vector<Edge> > &graph_) : graph(graph_) {
    n = graph.size();
    rev_graph.resize(n);
    REP(i, n) for (Edge &e : graph[i]) {
      rev_graph[e.dst].emplace_back(e.dst, e.src, e.cost);
    }
    used.resize(n);
    id.resize(n);
  }

  int build() {
    fill(ALL(used), false);
    order.clear();
    fill(ALL(id), -1);
    vertices.clear();
    comp.clear();
    REP(i, n) {
      if (!used[i]) dfs(i);
    }
    int now = 0;
    for (int i = n - 1; i >= 0; --i) {
      if (id[order[i]] == -1) {
        vertices.emplace_back();
        rev_dfs(order[i], now++);
      }
    }
    comp.resize(now);
    REP(i, n) for (Edge &e : graph[i]) {
      if (id[i] != id[e.dst]) comp[id[i]].emplace_back(id[i], id[e.dst], e.cost);
    }
    REP(i, now) sort(ALL(vertices[i]));
    return now;
  }

private:
  int n;
  vector<vector<Edge> > graph, rev_graph;
  vector<bool> used;
  vector<int> order;

  void dfs(int ver) {
    used[ver] = true;
    for (Edge &e : graph[ver]) {
      if (!used[e.dst]) dfs(e.dst);
    }
    order.emplace_back(ver);
  }

  void rev_dfs(int ver, int now) {
    id[ver] = now;
    vertices[now].emplace_back(ver);
    for (Edge &e : rev_graph[ver]) {
      if (id[e.dst] == -1) rev_dfs(e.dst, now);
    }
  }
};

struct TwoSat {
  TwoSat(int n) : n(n) { graph.resize(n * 2); }

  int negate(int x) { return (n + x) % (n * 2); }

  void add_if(int x, int y) { graph[x].emplace_back(x, y); }

  void add_or(int x, int y) {
    add_if(negate(x), y);
    add_if(negate(y), x);
  }

  void add_nand(int x, int y) { add_or(negate(x), negate(y)); }

  void set_true(int x) { add_if(negate(x), x); }

  void set_false(int x) { set_true(negate(x)); }

  vector<bool> build() {
    SCC scc(graph);
    scc.build();
    vector<bool> res(n);
    REP(i, n) {
      if (scc.id[i] == scc.id[negate(i)]) return {};
      res[i] = scc.id[negate(i)] < scc.id[i];
    }
    return res;
  }

private:
  int n;
  vector<vector<Edge> > graph;
};

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n, m; cin >> n >> m;
  vector<int> l(n), r(n); REP(i, n) cin >> l[i] >> r[i];
  TwoSat ts(n);
  REP(i, n) REP(j, i) {
    if (l[i] < r[j] && l[j] < r[i]) ts.add_nand(i, j);
    if (l[i] < m - l[j] - 1 && m - r[j] - 1 < r[i]) ts.add_nand(i, ts.negate(j));
    if (m - r[i] - 1 < r[j] && l[j] < m - l[i] - 1) ts.add_nand(ts.negate(i), j);
    if (m - r[i] - 1 < m - l[j] - 1 && m - r[j] - 1 < m - l[i] - 1) ts.add_nand(ts.negate(i), ts.negate(j));
  }
  cout << (ts.build().empty() ? "NO\n" : "YES\n");
  return 0;
}
0