結果

問題 No.274 The Wall
ユーザー oshiborioshibori
提出日時 2018-02-20 19:08:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 449 ms / 2,000 ms
コード長 2,306 bytes
コンパイル時間 2,080 ms
コンパイル使用メモリ 175,316 KB
実行使用メモリ 132,248 KB
最終ジャッジ日時 2023-09-04 02:29:14
合計ジャッジ時間 3,980 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 142 ms
68,464 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 449 ms
132,248 KB
testcase_12 AC 10 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 8 ms
4,380 KB
testcase_15 AC 18 ms
4,376 KB
testcase_16 AC 110 ms
39,424 KB
testcase_17 AC 101 ms
37,820 KB
testcase_18 AC 112 ms
40,696 KB
testcase_19 AC 33 ms
4,380 KB
testcase_20 AC 37 ms
4,380 KB
testcase_21 AC 39 ms
4,376 KB
testcase_22 AC 41 ms
4,376 KB
testcase_23 AC 41 ms
4,376 KB
testcase_24 AC 39 ms
4,380 KB
testcase_25 AC 41 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
// typedef __int128_t Int;
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
struct SCC {
  int V;
  vector<vector<int>> G, rG;
  vector<int> vs, cmp; // post order, topological order
  vector<bool> used;
  SCC() {}
  SCC(int V) : V(V), G(V), rG(V), used(V), cmp(V) {}
  void add_arc(int s, int t) {
    G[s].push_back(t);
    rG[t].push_back(s);
  }
  void dfs(int v) {
    used[v] = true;
    for (int i : G[v]) {
      if (not used[i])
        dfs(i);
    }
    vs.push_back(v);
  }
  void rdfs(int v, int k) {
    used[v] = true;
    cmp[v] = k;
    for (int i : rG[v]) {
      if (not used[i])
        rdfs(i, k);
    }
  }
  int scc() {
    fill(all(used), false);
    vs.clear();
    rep(v, 0, V) {
      if (not used[v])
        dfs(v);
    }
    fill(all(used), false);
    int k = 0;
    rrep(i, 0, vs.size()) {
      if (not used[vs[i]])
        rdfs(vs[i], k++);
    }
    return k;
  }
};
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  int N, M;
  cin >> N >> M;
  SCC g(N * 2);
  vector<int> l(2 * N), r(2 * N);
  rep(i, 0, N) {
    cin >> l[i] >> r[i];
    r[N + i] = M - 1 - l[i];
    l[N + i] = M - 1 - r[i];
  }
  dump(1);

  auto notidx = [&](int x) { return (x >= N ? x - N : x + N); };
  rep(i, 0, l.size()) rep(j, i + 1, l.size()) {
    bool f = r[i] < l[j] or r[j] < l[i];
    if (f)
      continue;

    // not i and j
    g.add_arc(i, notidx(j));
    g.add_arc(j, notidx(i));
  }
  dump(1);
  g.scc();
  bool f = true;
  rep(i, 0, N) { f &= g.cmp[i] != g.cmp[i + N]; }
  cout << (f ? "YES" : "NO") << endl;
  return 0;
}
0