結果

問題 No.274 The Wall
ユーザー 193s193s
提出日時 2017-05-17 17:55:33
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 504 ms / 2,000 ms
コード長 1,974 bytes
コンパイル時間 1,048 ms
コンパイル使用メモリ 90,560 KB
実行使用メモリ 132,236 KB
最終ジャッジ日時 2023-09-04 02:22:11
合計ジャッジ時間 3,648 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 157 ms
68,508 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 504 ms
132,236 KB
testcase_12 AC 63 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 11 ms
4,380 KB
testcase_15 AC 27 ms
4,376 KB
testcase_16 AC 105 ms
28,384 KB
testcase_17 AC 100 ms
28,228 KB
testcase_18 AC 106 ms
29,432 KB
testcase_19 AC 50 ms
4,380 KB
testcase_20 AC 58 ms
4,380 KB
testcase_21 AC 60 ms
4,376 KB
testcase_22 AC 63 ms
4,376 KB
testcase_23 AC 63 ms
4,376 KB
testcase_24 AC 63 ms
4,380 KB
testcase_25 AC 63 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N, M;
int L[4000], R[4000];
vector<int> vs;

class SAT2 {
public:
  int N;
  vector< vector<int> > G, R;
  vector<int> vs, used, ord;

  SAT2 (int N) : N(N) {
    G.resize(2*N);
    R.resize(2*N);
    used.resize(2*N);
    ord.resize(2*N);
  }

  void add_edge(int x, int y) {
    G[x].pb(y);
    R[y].pb(x);
  }

  void dfs(int x) {
    if (used[x]) return;
    used[x] = true;
    for (int t : G[x]) dfs(t);
    vs.pb(x);
  }
  void rdfs(int x, int k) {
    if (used[x]) return;
    used[x] = true;
    ord[x] = k;
    for (int t : R[x]) rdfs(t, k);
  }

  int scc() {
    rep(i, 2*N) used[i] = false;
    rep(i, 2*N) dfs(i);
    rep(i, 2*N) used[i] = false;
    int k = 0;
    for (int i=vs.size()-1; i>=0; i--) {
      if (!used[vs[i]]) rdfs(vs[i], k++);
    }
    return k;
  }

  bool is_sat() {
    scc();
    rep(i, N) {
      if (ord[i] == ord[i+N]) return false;
    }
    return true;
  }
};


signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N >> M;
  rep(i, N) {
    cin >> L[i] >> R[i];
    L[i+N] = M-1-R[i];
    R[i+N] = M-1-L[i];
  }

  SAT2 sat(N);
  for (int x=0; x<2*N; x++) {
    for (int y=x+1; y<2*N; y++) {
      if (x % N == y % N) continue;
      if (max(L[x], L[y]) > min(R[x], R[y])) continue;
      // (not x) | (not y)
      // x => not y, y => not x
      //cout<<(x>=N?"!":"")<<(x%N)<<"<->"<<(y>=N?"!":"")<<(y%N)<<"\n";
      sat.add_edge(x, (y+N)%(2*N));
      sat.add_edge(y, (x+N)%(2*N));
    }
  }
  if (sat.is_sat()) cout << "YES\n";
  else cout << "NO\n";
  return 0;
}
0