結果

問題 No.274 The Wall
ユーザー 👑 emthrmemthrm
提出日時 2019-09-17 01:49:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,064 bytes
コンパイル時間 1,161 ms
コンパイル使用メモリ 92,784 KB
実行使用メモリ 384,776 KB
最終ジャッジ日時 2023-09-21 09:08:36
合計ジャッジ時間 4,666 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 273 ms
168,668 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 WA -
testcase_06 AC 1 ms
4,380 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 1 ms
4,384 KB
testcase_10 WA -
testcase_11 AC 741 ms
384,776 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 177 ms
94,356 KB
testcase_17 AC 167 ms
90,444 KB
testcase_18 AC 181 ms
97,516 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 26 ms
4,376 KB
testcase_23 AC 26 ms
4,376 KB
testcase_24 WA -
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

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()
/*-------------------------------------------------*/
struct Edge {
  int src, dst;
  Edge(int src, int dst) : src(src), dst(dst) {}
};

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);
    }
    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_or(int x, int y) {
    graph[negate(x)].emplace_back(negate(x), y);
    graph[negate(y)].emplace_back(negate(y), x);
  }

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

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

  void set_true(int x) { add_or(x, x); }

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

  vector<bool> build() {
    SCC scc(graph);
    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