結果

問題 No.274 The Wall
ユーザー hashiryohashiryo
提出日時 2019-06-07 20:46:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 257 ms / 2,000 ms
コード長 2,043 bytes
コンパイル時間 2,125 ms
コンパイル使用メモリ 180,472 KB
実行使用メモリ 140,204 KB
最終ジャッジ日時 2023-09-04 02:38:46
合計ジャッジ時間 4,060 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 92 ms
60,636 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 257 ms
140,204 KB
testcase_12 AC 8 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 4 ms
4,380 KB
testcase_15 AC 8 ms
4,376 KB
testcase_16 AC 74 ms
37,264 KB
testcase_17 AC 68 ms
35,392 KB
testcase_18 AC 74 ms
38,164 KB
testcase_19 AC 15 ms
4,376 KB
testcase_20 AC 17 ms
4,376 KB
testcase_21 AC 17 ms
4,380 KB
testcase_22 AC 19 ms
4,380 KB
testcase_23 AC 19 ms
4,384 KB
testcase_24 AC 19 ms
4,380 KB
testcase_25 AC 19 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << '\n'
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 20171211;

struct Edge{
  ll dst;
  Edge(ll t):dst(t){}
};

using Edges=vector<Edge>;
using Graph=vector<Edges>;

vector<vector<int>> SCC(const Graph& g,vector<int> &I) {
    ll n=g.size();
    vector<vector<int>> scc;
    vector<int> S, B;
    I.assign(n,0);
    function<void(int)> dfs = [&](int u) {
        B.push_back(I[u] = S.size());
        S.push_back(u);
        for(Edge e: g[u]) {
            int v=e.dst;
            if (!I[v]) dfs(v);
            else while (I[v] < B.back()) B.pop_back();
        }
        if (I[u] == B.back()) {
            scc.push_back({});
            B.pop_back();
            for (; I[u] < (int)S.size(); S.pop_back()) {
                scc.back().push_back(S.back());
                I[S.back()] = n + scc.size();
            }
        }
    };
    for(int u=0;u<n;u++)if (!I[u]) dfs(u);
    for(int u=0;u<n;u++)I[u] -= n+1;
    return scc;
}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N,M;cin>>N>>M;
  vll L(N),R(N);
  for(ll i=0;i<N;i++){
    cin>>L[i]>>R[i];
  }
  Graph G(2*N);
  for(ll i=0;i<N;i++){
    for(ll j=i+1;j<N;j++){
      if(L[i]<=R[j]&&L[j]<=R[i])G[i].emplace_back(N+j),G[N+j].emplace_back(i);
      if(L[i]<=(M-1-L[j])&&(M-1-R[j])<=R[i])G[i].emplace_back(j),G[j].emplace_back(i);
      if((M-1-R[i])<=R[j]&&L[j]<=(M-1-L[i]))G[N+i].emplace_back(N+j),G[N+j].emplace_back(N+i);
      if((M-1-R[i])<=(M-1-L[j])&&(M-1-R[j])<=(M-1-L[i]))G[N+1].emplace_back(j),G[j].emplace_back(N+i);
    }
  }
  vector<int> idx;
  vector<vector<int>> scc=SCC(G,idx);
  /*
  debug(scc.size());
  debugArray(idx,N*2);
  */
  bool isok=true;
  for(ll i=0;i<N;i++){
    isok &= idx[i]!=idx[N+i];
  }
  cout<<(isok? "YES":"NO")<<endl;
  return 0;
}
0