結果
問題 | No.274 The Wall |
ユーザー |
![]() |
提出日時 | 2018-11-18 12:51:18 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 354 ms / 2,000 ms |
コード長 | 2,819 bytes |
コンパイル時間 | 1,262 ms |
コンパイル使用メモリ | 82,716 KB |
実行使用メモリ | 132,224 KB |
最終ジャッジ日時 | 2024-06-22 02:25:10 |
合計ジャッジ時間 | 3,290 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 22 |
コンパイルメッセージ
main.cpp:13:29: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts' 13 | void Dfs(const int cur, auto &ord) { | ^~~~ main.cpp:61:22: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts' 61 | inline bool Is(const auto &s1, const auto &s2) { | ^~~~ main.cpp:61:38: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts' 61 | inline bool Is(const auto &s1, const auto &s2) { | ^~~~
ソースコード
#include <iostream>#include <vector>struct Graph {const int n;std::vector<std::vector<int>> adj, radj;std::vector<int> scc;Graph(int _n) : n(_n), adj(n), radj(n), scc(n, false) {}void add_edge(int src, int dst) { adj[src].push_back(dst); radj[dst].push_back(src); }void Dfs(const int cur, auto &ord) {scc[cur] = true;for (auto dst : adj[cur])if (!scc[dst]) Dfs(dst, ord);ord.push_back(cur);}void RevDfs(const int id, const int cur) {scc[cur] = id;for (auto dst : radj[cur])if (scc[dst] == -1) RevDfs(id, dst);}void StronglyConnectedComponents() {std::vector<int> ord;for (int v = 0; v < n; ++v)if (!scc[v]) Dfs(v, ord);std::fill(scc.begin(), scc.end(), -1);for (int i = n - 1, no = 0; 0 <= i; --i)if (scc[ord[i]] == -1) RevDfs(no++, ord[i]);}};// -------------8<------- start of library -------8<------------------------struct TwoSat {const int n;std::vector<bool> sol;Graph g;TwoSat(int _n) : n(_n), sol(n + 1, true), g(2 * n) {}void add_closure(int x1, bool lt1, int x2, bool lt2) {g.add_edge(x1 + (lt1 ? n : 0), x2 + (lt2 ? 0 : n));g.add_edge(x2 + (lt2 ? n : 0), x1 + (lt1 ? 0 : n));}bool Check() const { return sol[n]; }bool Solve() {g.StronglyConnectedComponents();for (int x = 0; x < n; ++x) {if (g.scc[x] == g.scc[x + n]) return sol[n] = false;sol[x] = (g.scc[x] > g.scc[x + n]);}return sol[n];}};// -------------8<------- end of library ---------8-------------------------inline bool Is(const auto &s1, const auto &s2) {return (s1.first <= s2.first && s2.first <= s1.second) ||(s1.first <= s2.second && s2.second <= s1.second) ||(s2.first <= s1.first && s1.first <= s2.second) ||(s2.first <= s1.second && s1.second <= s2.second);}int main() {std::cin.tie(0); std::ios::sync_with_stdio(false);int n, m;std::cin >> n >> m;std::vector<std::pair<int, int>> seg(n), rseg(n);for (int i = 0; i < n; ++i) {std::cin >> seg[i].first >> seg[i].second;rseg[i] = std::make_pair(m - 1 - seg[i].second, m - 1 - seg[i].first);}TwoSat sat(n);for (int i = 0; i < n; ++i) {for (int j = i + 1; j < n; ++j) {if (Is(seg[i], seg[j])) sat.add_closure(i, false, j, false);if (Is(seg[i], rseg[j])) sat.add_closure(i, false, j, true);if (Is(rseg[i], seg[j])) sat.add_closure(i, true, j, false);if (Is(rseg[i], rseg[j])) sat.add_closure(i, true, j, true);}}std::cout << (sat.Solve() ? "YES" : "NO") << std::endl;return 0;}