結果

問題 No.274 The Wall
ユーザー どららどらら
提出日時 2018-12-18 01:42:58
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,695 bytes
コンパイル時間 2,166 ms
コンパイル使用メモリ 184,964 KB
実行使用メモリ 68,468 KB
最終ジャッジ日時 2023-10-25 23:33:48
合計ジャッジ時間 4,600 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 WA -
testcase_03 AC 75 ms
40,840 KB
testcase_04 WA -
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 208 ms
68,468 KB
testcase_12 AC 15 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 5 ms
4,348 KB
testcase_15 AC 10 ms
4,348 KB
testcase_16 AC 107 ms
42,760 KB
testcase_17 AC 94 ms
38,728 KB
testcase_18 AC 102 ms
42,664 KB
testcase_19 AC 16 ms
4,348 KB
testcase_20 AC 18 ms
4,348 KB
testcase_21 AC 20 ms
4,348 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 20 ms
4,348 KB
testcase_25 AC 20 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, n) for (int i = (a); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define FOR(it, c) \
  for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

class Solver2SAT {
  std::vector<std::vector<int>> G, rG;
  std::vector<int> vs;
  std::vector<bool> used;
  std::vector<int> cmp;

  void dfs(int v) {
    used[v] = true;
    for (int i = 0; i < G[v].size(); i++)
      if (!used[G[v][i]]) dfs(G[v][i]);
    vs.push_back(v);
  }

  void rdfs(int v, int k) {
    used[v] = true;
    cmp[v] = k;
    for (int i = 0; i < rG[v].size(); i++)
      if (!used[rG[v][i]]) rdfs(rG[v][i], k);
  }

  void clear() {
    G.clear();
    rG.clear();
    vs.clear();
    used.clear();
    cmp.clear();
  }

  int scc() {
    for (int v = 0; v < G.size(); v++)
      if (!used[v]) dfs(v);
    used.clear();
    used.resize(G.size(), false);
    int k = 0;
    for (int i = vs.size() - 1; i >= 0; i--)
      if (!used[vs[i]]) rdfs(vs[i], k++);
    return k;
  }

 public:
  void init(int N) {
    clear();
    G.resize(N);
    rG.resize(N);
    used.resize(N, false);
    cmp.resize(N, 0);
  }

  void add_edge(int from, int to) {
    G[from].push_back(to);
    rG[to].push_back(from);
  }

  std::vector<bool> solve() {
    scc();
    for (int i = 0; i < G.size() / 2; i++) {
      if (cmp[i] == cmp[G.size() / 2 + i]) return std::vector<bool>();
    }
    std::vector<bool> ret(G.size() / 2);
    for (int i = 0; i < G.size() / 2; i++) {
      if (cmp[i] > cmp[G.size() / 2 + i])
        ret[i] = true;
      else
        ret[i] = false;
    }
    return ret;
  }
};

bool check(int li, int ri, int lj, int rj) {
  return (li <= lj && lj <= ri) || (li <= rj && rj <= ri);
}

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> v;
  rep(i, N) {
    int l, r;
    cin >> l >> r;
    v.push_back({l, r});
  }

  Solver2SAT sat;
  sat.init(2 * N);
  rep(i, N) {
    REP(j, i + 1, N) {
      int a = i;
      int na = N + i;
      int b = j;
      int nb = N + j;
      bool flgTT = check(v[i][0], v[i][1], v[j][0], v[j][1]);
      bool flgFT = check(M - 1 - v[i][0], M - 1 - v[i][1], v[j][0], v[j][1]);

      if (flgTT) {
        sat.add_edge(na, b);
        sat.add_edge(nb, a);
        sat.add_edge(a, nb);
        sat.add_edge(b, na);
      }
      if (flgFT) {
        sat.add_edge(na, nb);
        sat.add_edge(b, a);
        sat.add_edge(a, b);
        sat.add_edge(nb, na);
      }
    }
  }
  vector<bool> ret = sat.solve();
  if (ret.size() != 0)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;

  return 0;
}
0