結果

問題 No.274 The Wall
ユーザー nmnmnmnmnmnmnmnmnmnmnmnmnmnm
提出日時 2015-07-08 00:27:05
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 2,425 bytes
コンパイル時間 997 ms
コンパイル使用メモリ 92,784 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-22 09:25:32
合計ジャッジ時間 2,857 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <cassert>
 
using namespace std;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
 
#define MOD 1000000007

#define MAX_V 200

vector<int> graph[MAX_V];
vector<int> rev_graph[MAX_V];
bool visited[MAX_V];
int cmp[MAX_V];
vector<int> st;

void ae(int from, int to){
  graph[from].pb(to);
  rev_graph[to].pb(from);
}

void dfs(int v){
  visited[v] = true;
  for(int i=0; i<(int)graph[v].size(); i++){
    int u = graph[v][i]; 
    if(!visited[u]){
      dfs(u);
    }
  }
  st.push_back(v);
}

void rev_dfs(int v, int cnt){
  visited[v] = true;
  for(int i=0; i<(int)rev_graph[v].size(); i++){
    int u = rev_graph[v][i];
    if(!visited[u]){
      rev_dfs(u, cnt);
    }
  }
  cmp[v] = cnt;
}

void scc(){
  memset(visited, 0, sizeof(visited));
  memset(cmp, 0, sizeof(cmp));
  st.clear();

  for(int i=0; i<MAX_V; i++){
    if(!visited[i]){
      dfs(i);
    }
  }

  memset(visited, 0, sizeof(visited));
  int cnt = 0;
  while(!st.empty()){
    int v = st.back();
    st.pop_back();
    if(!visited[v]){
      rev_dfs(v, cnt++);
    }
  }
}

int n,m;

int rev(int p){
  return m-p-1;
}

int main(){
  cin>>n>>m;
  if(n>100)return -1;
  if(m>1000)return -1;
  vector<int> vl;
  vector<int> vr;
  rep(i,0,n){
    int l,r;
    cin>>l>>r;
    if(l>=m)return -1;
    if(r>=m)return -1;
    vl.pb(l);
    vr.pb(r);
  }
  rep(i,0,n){
    rep(j,i+1,n){
      if(vl[i]<=vr[j]&&vl[j]<=vr[i]){
        ae(j,100+i);
        ae(i,100+j);
      }
      if(rev(vr[i])<=vr[j]&&vl[j]<=rev(vl[i])){
        ae(j,i);
        ae(100+i,100+j);
      }
      if(vl[i]<=rev(vl[j])&&rev(vr[j])<=vr[i]){
        ae(100+j,100+i);
        ae(i,j);
      }
      if(rev(vr[i])<=rev(vl[j])&&rev(vr[j])<=rev(vl[i])){
        ae(100+i,j);
        ae(100+j,i);
      }
    }
  }
  scc();
  rep(i,0,n){
    if(cmp[i]==cmp[100+i]){
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}
0