結果

問題 No.274 The Wall
ユーザー beetbeet
提出日時 2018-12-06 16:37:44
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 571 ms / 2,000 ms
コード長 1,976 bytes
コンパイル時間 2,585 ms
コンパイル使用メモリ 215,236 KB
実行使用メモリ 260,608 KB
最終ジャッジ日時 2023-09-04 02:34:48
合計ジャッジ時間 5,043 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 208 ms
116,820 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,504 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 571 ms
260,608 KB
testcase_12 AC 25 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 6 ms
4,376 KB
testcase_15 AC 12 ms
4,380 KB
testcase_16 AC 101 ms
48,636 KB
testcase_17 AC 99 ms
48,112 KB
testcase_18 AC 103 ms
50,364 KB
testcase_19 AC 21 ms
4,380 KB
testcase_20 AC 23 ms
4,376 KB
testcase_21 AC 24 ms
4,376 KB
testcase_22 AC 26 ms
4,376 KB
testcase_23 AC 26 ms
4,376 KB
testcase_24 AC 25 ms
4,380 KB
testcase_25 AC 26 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


struct SCC{
  Int n;
  vector<vector<Int> > G,rG,T,C;
  vector<Int> vs,used,blg;
  SCC(){}
  SCC(Int n):n(n),G(n),rG(n),used(n),blg(n){}
  
  void add_edge(Int from,Int to){
    G[from].emplace_back(to);
    rG[to].emplace_back(from);
  }
  
  void dfs(Int v){
    used[v]=1;
    for(Int u:G[v])
      if(!used[u]) dfs(u);
    vs.emplace_back(v);
  }
  
  void rdfs(Int v,Int k){
    used[v]=1;
    blg[v]=k;
    C[k].emplace_back(v);
    for(Int u:rG[v])
      if(!used[u]) rdfs(u,k);
  }
  
  Int build(){
    for(Int v=0;v<n;v++)
      if(!used[v]) dfs(v);
    
    fill(used.begin(),used.end(),0);
    Int k=0;
    for(Int i=vs.size()-1;i>=0;i--){
      if(!used[vs[i]]){
        T.emplace_back();
        C.emplace_back();
        rdfs(vs[i],k++);
      }
    }
    for(Int v=0;v<n;v++)
      for(Int u:G[v])
        if(blg[v]!=blg[u])
          T[blg[v]].push_back(blg[u]);
    
    for(Int i=0;i<k;i++){
      sort(T[i].begin(),T[i].end());
      T[i].erase(unique(T[i].begin(),T[i].end()),T[i].end());
    }
    return k;
  }
};

//INSERT ABOVE HERE
signed main(){
  Int n,m;
  cin>>n>>m;
  vector<Int> l(n),r(n);
  for(Int i=0;i<n;i++) cin>>l[i]>>r[i],r[i]++;

  auto check=[&](Int al,Int ar,Int bl,Int br){
               return max(al,bl)<min(ar,br);};
  
  SCC scc(n*2);
  for(Int i=0;i<n;i++){
    for(Int j=0;j<n;j++){
      if(i==j) continue;
      if(check(l[i],r[i],l[j],r[j])) scc.add_edge(i,j+n);
      if(check(l[i],r[i],m-r[j],m-l[j])) scc.add_edge(i,j);
      if(check(m-r[i],m-l[i],l[j],r[j])) scc.add_edge(i+n,j+n);
      if(check(m-r[i],m-l[i],m-r[j],m-l[j])) scc.add_edge(i+n,j);
    }    
  }

  scc.build();
  Int flg=0;
  for(Int i=0;i<n;i++) flg|=scc.blg[i]==scc.blg[i+n];

  cout<<(flg?"NO":"YES")<<endl;
  return 0;
}
0