結果

問題 No.274 The Wall
ユーザー 193s193s
提出日時 2017-05-17 17:54:59
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,999 bytes
コンパイル時間 1,041 ms
コンパイル使用メモリ 92,624 KB
実行使用メモリ 132,344 KB
最終ジャッジ日時 2023-10-17 23:58:57
合計ジャッジ時間 3,978 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

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++);
    }
    cout<<"k="<<k<<"\n";
    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