結果

問題 No.274 The Wall
ユーザー null_nullnull_null
提出日時 2018-12-23 23:19:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 610 ms / 2,000 ms
コード長 4,153 bytes
コンパイル時間 1,500 ms
コンパイル使用メモリ 168,520 KB
実行使用メモリ 265,780 KB
最終ジャッジ日時 2023-09-04 02:34:42
合計ジャッジ時間 3,806 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
9,308 KB
testcase_01 AC 4 ms
9,468 KB
testcase_02 AC 4 ms
9,380 KB
testcase_03 AC 223 ms
131,556 KB
testcase_04 AC 4 ms
9,368 KB
testcase_05 AC 4 ms
9,360 KB
testcase_06 AC 4 ms
9,320 KB
testcase_07 AC 4 ms
9,296 KB
testcase_08 AC 4 ms
9,324 KB
testcase_09 AC 5 ms
9,340 KB
testcase_10 AC 4 ms
9,364 KB
testcase_11 AC 610 ms
265,780 KB
testcase_12 AC 15 ms
9,444 KB
testcase_13 AC 4 ms
9,620 KB
testcase_14 AC 6 ms
9,468 KB
testcase_15 AC 10 ms
9,524 KB
testcase_16 AC 88 ms
53,844 KB
testcase_17 AC 87 ms
53,324 KB
testcase_18 AC 91 ms
55,160 KB
testcase_19 AC 13 ms
9,676 KB
testcase_20 AC 15 ms
9,692 KB
testcase_21 AC 16 ms
9,660 KB
testcase_22 AC 16 ms
9,712 KB
testcase_23 AC 16 ms
9,620 KB
testcase_24 AC 16 ms
9,652 KB
testcase_25 AC 16 ms
9,660 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;

//
#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0, sizeof(x))
#define mm(x) memset((x), -1, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define bit(n) (1LL << (n))
#define bitset(a, b) (a) |= (1 << (b))
#define bitunset(a, b) (a) |= ~(1 << (b))
#define bitcheck(a, b) ((((a) >> (b)) & 1) == 1)
#define bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
const int INF = (int)1e18;
const int MOD = (int)1e9 + 7;
const double EPS = (double)1e-10;
const int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};

//O(N)
//充足可能性問題を解く。

//O(V+E)
//強連結成分分解
const int MAX_V = 101010;

int V;                 //頂点数
vector<int> G[MAX_V];  //グラフの辺
vector<int> rG[MAX_V]; //逆向きの辺
vector<int> vs;        //帰りがけ順の並び
bool used[MAX_V];      //既に調べたかどうか
int cmp[MAX_V];        //属する強連結成分のトポロジカル順序

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

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 scc() {
  memset(used, 0, sizeof(used));
  vs.clear();
  for (int v = 0; v < V; v++) {
    if (!used[v]) dfs(v);
  }
  memset(used, 0, sizeof(used));
  int k = 0;
  for (int i = vs.size() - 1; i >= 0; i--) {
    if (!used[vs[i]]) rdfs(vs[i], k++);
  }
  return;
}

///////////////////////////////////////////////////////////////////////
//ここからSAT

int N; //リテラルの要素数。
int L[101010], R[101010], D[101010];

void solve() {
  V = 2 * N;
  //各リテラルをxで表す。対応は以下の通り
  //0~N-1  :  x_i
  //N~2*N-1: ¬x_i

  //以下xリテラルの入力
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < i; j++) {
      if (max(L[i], L[j]) <= min(L[i] + D[i], L[j] + D[j])) {
        add_edge(i + N, j);
        add_edge(j + N, i);
      }
      if (max(R[i], R[j]) <= min(R[i] + D[i], R[j] + D[j])) {
        add_edge(i, j + N);
        add_edge(j, i + N);
      }
      if (max(R[i], L[j]) <= min(R[i] + D[i], L[j] + D[j])) {
        add_edge(i, j);
        add_edge(j + N, i + N);
      }
      if (max(L[i], R[j]) <= min(L[i] + D[i], R[j] + D[j])) {
        add_edge(j, i);
        add_edge(i + N, j + N);
      }
    }
  }

  //強連結成分分解
  scc();

  for (int i = 0; i < N; i++) {
    if (cmp[i] == cmp[N + i]) {
      cout << "NO" << endl;
      return;
    }
  }

  cout << "YES" << endl;
}

signed main() {
  int M;
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    int l, r;
    cin >> l >> r;
    D[i] = r - l;
    L[i] = l;
    R[i] = M - 1 - r;
  }

  solve();

  return 0;
}
0