結果
問題 | No.274 The Wall |
ユーザー |
![]() |
提出日時 | 2018-02-28 02:35:02 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,514 bytes |
コンパイル時間 | 2,419 ms |
コンパイル使用メモリ | 193,548 KB |
実行使用メモリ | 132,352 KB |
最終ジャッジ日時 | 2024-12-14 14:20:18 |
合計ジャッジ時間 | 4,371 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 20 WA * 2 |
ソースコード
#include <bits/stdc++.h>using namespace std;#define INF_LL (int64)1e18#define INF (int32)1e9#define REP(i, n) for(int i = 0;i < (n);i++)#define FOR(i, a, b) for(int i = (a);i < (b);i++)#define all(x) x.begin(),x.end()using int32 = int_fast32_t;using uint32 = uint_fast32_t;using int64 = int_fast64_t;using uint64 = uint_fast64_t;using PII = pair<int32, int32>;using PLL = pair<int64, int64>;#define fs first#define sc secondconst double eps = 1e-10;template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}class SCC{private:vector<vector<int> > gg, rg;vector<int> order, comp;vector<bool> used;vector<vector<int> > ng, vs;int n, nn;public:SCC(){}SCC(int v) : gg(v), rg(v), comp(v, -1), used(v, 0), n(v){}void add_edge(int x, int y){gg[x].push_back(y);rg[y].push_back(x);}int operator[](int k){return comp[k];}void dfs(int v){used[v] = true;REP(i, gg[v].size()){if(!used[gg[v][i]]) dfs(gg[v][i]);}order.push_back(v);}void rdfs(int v, int k){used[v] = true;comp[v] = k;REP(i, rg[v].size()){if(!used[rg[v][i]]) rdfs(rg[v][i], k);}}int build(){REP(i, n){if(!used[i]) dfs(i);}fill(all(used), 0);int k = 0;for(int i = order.size()-1;i >= 0;i--){if(!used[order[i]]) rdfs(order[i], k++);}nn = k;//---------それぞれの強連結成分に含まれる頂点の番号----------vs.resize(k, vector<int>());REP(i, n)vs[comp[i]].push_back(i);//-----------------------------------------------------------//---------強連結成分をまとめた後のNew Graph!----------------ng.resize(k, vector<int>());REP(i, n){REP(j, gg[i].size()){if(comp[i] != comp[gg[i][j]])ng[comp[i]].push_back(comp[gg[i][j]]);}}REP(i, nn){sort(all(ng[i]));ng[i].erase(unique(all(ng[i])), ng[i].end());}//------------------------------------------------------------return k;}int size(){return nn;}vector<vector<int> > graph(){return ng;}vector<int> vertices(int v){return vs[v];}};class TwoSAT{private:SCC scc;int n;vector<bool> truth;public:TwoSAT(){}TwoSAT(int _n) : n(_n), scc(2*_n){}void add_state(int a, bool truth1, int b, bool truth2){int na = truth1 ? a+n : a, nb = truth2 ? b+n : b;a = truth1 ? a : a+n; b = truth2 ? b : b+n;scc.add_edge(na, b);scc.add_edge(nb, a);}bool build(){scc.build();REP(i, n){if(scc[i] == scc[i+n]) return false;if(scc[i] > scc[i+n]) truth.push_back(true);else truth.push_back(false);}return true;}vector<bool> result(){return truth;}bool operator[](int k){return truth[k];}};int main(void){cin.tie(0);ios::sync_with_stdio(false);int32 N, M;cin >> N >> M;vector<PII> wall;wall.resize(N);REP(i, N)cin >> wall[i].fs >> wall[i].sc;TwoSAT scc(N);REP(i, N){FOR(j, i+1, N){if(i == j) continue;PII rw1(M-wall[i].sc-1, M-wall[i].fs-1), rw2(M-wall[j].sc-1, M-wall[j].fs-1);if(!(wall[j].sc < wall[i].fs) && !(wall[i].sc < wall[j].fs)) scc.add_state(i, 0, j, 0);if(!(wall[j].sc < rw1.fs) && !(rw1.sc < wall[j].fs)) scc.add_state(i, 1, j, 0);if(!(rw2.sc < wall[i].fs) && !(wall[i].sc < rw2.fs)) scc.add_state(i, 0, j, 1);if(!(rw2.sc < rw1.fs) && !(rw1.sc < rw2.sc)) scc.add_state(i, 1, j, 1);}}if(scc.build())cout << "YES" << endl;elsecout << "NO" << endl;}