結果
| 問題 |
No.274 The Wall
|
| ユーザー |
tatanaideyo
|
| 提出日時 | 2018-11-18 11:10:31 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,759 bytes |
| コンパイル時間 | 1,045 ms |
| コンパイル使用メモリ | 80,984 KB |
| 実行使用メモリ | 132,224 KB |
| 最終ジャッジ日時 | 2024-12-24 14:52:46 |
| 合計ジャッジ時間 | 3,546 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 21 WA * 1 |
コンパイルメッセージ
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:63:22: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts'
63 | inline bool Is(const auto &s1, const auto &s2) {
| ^~~~
main.cpp:63:38: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts'
63 | 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;
bool is_sat;
std::vector<bool> sol;
Graph g;
TwoSat(int _n) : n(_n), is_sat(true), sol(n, true), g(2 * n) {}
void add_closure(int x1, bool lt1, int x2, bool lt2) {
g.add_edge((x1 + n * !lt1 + n) % (2 * n), x2 + n * !lt2);
g.add_edge((x2 + n * !lt2 + n) % (2 * n), x1 + n * !lt1);
}
bool Check() const { return is_sat; }
bool Solve() {
g.StronglyConnectedComponents();
for (int x = 0; x < n; ++x) {
if (g.scc[x] == g.scc[x + n]) is_sat = false;
else if (g.scc[x] < g.scc[x + n]) sol[x] = false;
}
return is_sat;
}
};
// -------------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);
}
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);
}
}
if (sat.Solve()) std::cout << "YES\n";
else std::cout << "NO\n";
return 0;
}
tatanaideyo