結果
問題 | No.274 The Wall |
ユーザー | pazzle1230 |
提出日時 | 2018-02-28 02:35:02 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,514 bytes |
コンパイル時間 | 2,462 ms |
コンパイル使用メモリ | 191,832 KB |
実行使用メモリ | 132,480 KB |
最終ジャッジ日時 | 2024-05-08 10:58:24 |
合計ジャッジ時間 | 4,524 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | WA | - |
testcase_03 | AC | 144 ms
60,032 KB |
testcase_04 | AC | 2 ms
6,940 KB |
testcase_05 | AC | 2 ms
6,944 KB |
testcase_06 | AC | 2 ms
6,940 KB |
testcase_07 | AC | 2 ms
6,944 KB |
testcase_08 | AC | 2 ms
6,940 KB |
testcase_09 | AC | 2 ms
6,944 KB |
testcase_10 | AC | 2 ms
6,940 KB |
testcase_11 | AC | 435 ms
132,480 KB |
testcase_12 | AC | 13 ms
6,940 KB |
testcase_13 | AC | 2 ms
6,944 KB |
testcase_14 | AC | 5 ms
6,940 KB |
testcase_15 | AC | 11 ms
6,940 KB |
testcase_16 | AC | 111 ms
36,864 KB |
testcase_17 | AC | 104 ms
35,712 KB |
testcase_18 | AC | 116 ms
38,528 KB |
testcase_19 | AC | 19 ms
6,940 KB |
testcase_20 | AC | 22 ms
6,944 KB |
testcase_21 | AC | 22 ms
6,944 KB |
testcase_22 | WA | - |
testcase_23 | AC | 23 ms
6,944 KB |
testcase_24 | AC | 23 ms
6,940 KB |
testcase_25 | AC | 23 ms
6,940 KB |
ソースコード
#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 second const 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; else cout << "NO" << endl; }