結果
問題 | No.274 The Wall |
ユーザー | snbn |
提出日時 | 2020-07-27 21:46:26 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 114 ms / 2,000 ms |
コード長 | 3,611 bytes |
コンパイル時間 | 1,035 ms |
コンパイル使用メモリ | 107,952 KB |
実行使用メモリ | 67,840 KB |
最終ジャッジ日時 | 2024-06-22 02:38:47 |
合計ジャッジ時間 | 2,366 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 45 ms
33,664 KB |
testcase_04 | AC | 2 ms
6,944 KB |
testcase_05 | AC | 1 ms
6,944 KB |
testcase_06 | AC | 1 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,940 KB |
testcase_10 | AC | 2 ms
6,940 KB |
testcase_11 | AC | 114 ms
67,840 KB |
testcase_12 | AC | 15 ms
6,940 KB |
testcase_13 | AC | 2 ms
6,944 KB |
testcase_14 | AC | 7 ms
6,944 KB |
testcase_15 | AC | 16 ms
6,944 KB |
testcase_16 | AC | 64 ms
20,992 KB |
testcase_17 | AC | 61 ms
20,096 KB |
testcase_18 | AC | 66 ms
21,632 KB |
testcase_19 | AC | 31 ms
6,940 KB |
testcase_20 | AC | 34 ms
6,940 KB |
testcase_21 | AC | 33 ms
6,944 KB |
testcase_22 | AC | 35 ms
6,944 KB |
testcase_23 | AC | 36 ms
6,944 KB |
testcase_24 | AC | 37 ms
6,944 KB |
testcase_25 | AC | 36 ms
6,940 KB |
ソースコード
#include <algorithm> #include <bitset> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <queue> #include <set> #include <tuple> #include <vector> using namespace std; #define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++) #define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++) #define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--) #define rirep(i, n) for (int64_t i = n; i >= 0; i--) #define chmax(a, b) (a) = max(a, b) #define chmin(a, b) (a) = min(a, b) vector<vector<int>> inversed_edge(const vector<vector<int>> &edge) { vector<vector<int>> result(edge.size()); for (int i = 0; i < edge.size(); i++) { for (int from : edge[i]) { result[from].push_back(i); } } return result; } class TopologicalSort { const vector<vector<int>> &mOutEdge; vector<int> mIsVisited; public: TopologicalSort(const TopologicalSort &) = delete; TopologicalSort &operator=(const TopologicalSort &) = delete; TopologicalSort(TopologicalSort &&) = delete; TopologicalSort &operator=(TopologicalSort &&) = delete; explicit TopologicalSort(const vector<vector<int>> &outEdge) : mOutEdge(outEdge), mIsVisited(outEdge.size()) {} vector<int> build() { const int N = mIsVisited.size(); fill(mIsVisited.begin(), mIsVisited.end(), false); vector<int> sorted; for (int i = 0; i < N; i++) { if (!mIsVisited[i]) { dfs(i, sorted); } } return sorted; } private: void dfs(int node, vector<int> &sorted) { mIsVisited[node] = true; for (int c : mOutEdge[node]) { if (!mIsVisited[c]) { dfs(c, sorted); } } sorted.push_back(node); } }; class StrictlyConnectedComponent { const vector<vector<int>> &mInEdge; const vector<int> mSorted; vector<int> mIsVisited; public: StrictlyConnectedComponent(const StrictlyConnectedComponent &) = delete; StrictlyConnectedComponent &operator=(const StrictlyConnectedComponent &) = delete; StrictlyConnectedComponent(StrictlyConnectedComponent &&) = delete; StrictlyConnectedComponent &operator=(StrictlyConnectedComponent &&) = delete; explicit StrictlyConnectedComponent(const vector<vector<int>> &inEdge, const vector<int> &sorted) : mInEdge(inEdge), mSorted(sorted), mIsVisited(inEdge.size()) {} vector<int> build() { const int N = mIsVisited.size(); vector<int> group(N); fill(mIsVisited.begin(), mIsVisited.end(), false); for (int i = N - 1; i >= 0; i--) { if (!mIsVisited[mSorted[i]]) { dfs(mSorted[i], i, group); } } return group; } private: void dfs(int node, int curr, vector<int> &group) { mIsVisited[node] = true; group[node] = curr; for (int c : mInEdge[node]) { if (!mIsVisited[c]) { dfs(c, curr, group); } } } }; int main() { int N, M; cin >> N >> M; vector<int> l(N), r(N); rep(i, N) { cin >> l[i] >> r[i]; } vector<vector<int>> edge(2 * N); rep(i, N) rep(j, N) { if (i != j) { if (!(r[i] < l[j] || r[j] < l[i])) { edge[i].push_back(j + N); edge[i + N].push_back(j); } if (!(r[i] < M - r[j] - 1 || M - l[j] - 1 < l[i])) { edge[i].push_back(j); edge[i + N].push_back(j + N); } } } auto sorted = TopologicalSort(edge).build(); auto group = StrictlyConnectedComponent(edge, sorted).build(); bool result = true; rep(i, N) { result = result && (group[i] != group[i + N]); } cout << (result ? "YES" : "NO") << endl; return 0; }