結果
| 問題 |
No.274 The Wall
|
| コンテスト | |
| ユーザー |
emthrm
|
| 提出日時 | 2019-09-06 04:03:57 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 3,701 bytes |
| コンパイル時間 | 2,852 ms |
| コンパイル使用メモリ | 92,760 KB |
| 最終ジャッジ日時 | 2025-01-07 16:34:03 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 21 MLE * 1 |
ソースコード
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
/*-------------------------------------------------*/
using CostType = long long;
struct Edge {
int src, dst; CostType cost;
Edge(int src, int dst, CostType cost = 0) : src(src), dst(dst), cost(cost) {}
inline bool operator<(const Edge &rhs) const {
return cost != rhs.cost ? cost < rhs.cost : dst != rhs.dst ? dst < rhs.dst : src < rhs.src;
}
inline bool operator<=(const Edge &rhs) const { return cost <= rhs.cost; }
inline bool operator>(const Edge &rhs) const {
return cost != rhs.cost ? cost > rhs.cost : dst != rhs.dst ? dst > rhs.dst : src > rhs.src;
}
inline bool operator>=(const Edge &rhs) const { return cost >= rhs.cost; }
};
struct SCC {
vector<int> id;
// vector<vector<int> > vertices;
vector<vector<Edge> > comp;
SCC(const vector<vector<Edge> > &graph_) : graph(graph_) {
n = graph.size();
rev_graph.resize(n);
REP(i, n) for (Edge &e : graph[i]) {
rev_graph[e.dst].emplace_back(e.dst, e.src, e.cost);
}
used.resize(n);
id.resize(n);
}
int build() {
fill(ALL(used), false);
order.clear();
fill(ALL(id), -1);
// vertices.clear();
comp.clear();
REP(i, n) {
if (!used[i]) dfs(i);
}
int now = 0;
for (int i = n - 1; i >= 0; --i) {
if (id[order[i]] == -1) {
// vertices.emplace_back();
rev_dfs(order[i], now++);
}
}
comp.resize(now);
REP(i, n) for (Edge &e : graph[i]) {
if (id[i] != id[e.dst]) comp[id[i]].emplace_back(id[i], id[e.dst], e.cost);
}
// REP(i, now) sort(ALL(vertices[i]));
return now;
}
private:
int n;
vector<vector<Edge> > graph, rev_graph;
vector<bool> used;
vector<int> order;
void dfs(int ver) {
used[ver] = true;
for (Edge &e : graph[ver]) {
if (!used[e.dst]) dfs(e.dst);
}
order.emplace_back(ver);
}
void rev_dfs(int ver, int now) {
id[ver] = now;
// vertices[now].emplace_back(ver);
for (Edge &e : rev_graph[ver]) {
if (id[e.dst] == -1) rev_dfs(e.dst, now);
}
}
};
struct TwoSat {
TwoSat(int n) : n(n) { graph.resize(n * 2); }
int negate(int x) { return (n + x) % (n * 2); }
void add_if(int x, int y) { graph[x].emplace_back(x, y); }
void add_or(int x, int y) {
add_if(negate(x), y);
add_if(negate(y), x);
}
void add_nand(int x, int y) { add_or(negate(x), negate(y)); }
void set_true(int x) { add_if(negate(x), x); }
void set_false(int x) { set_true(negate(x)); }
vector<bool> build() {
SCC scc(graph);
scc.build();
vector<bool> res(n);
REP(i, n) {
if (scc.id[i] == scc.id[negate(i)]) return {};
res[i] = scc.id[negate(i)] < scc.id[i];
}
return res;
}
private:
int n;
vector<vector<Edge> > graph;
};
int main() {
cin.tie(nullptr); ios::sync_with_stdio(false);
// freopen("input.txt", "r", stdin);
int n, m; cin >> n >> m;
vector<int> l(n), r(n); REP(i, n) cin >> l[i] >> r[i];
TwoSat ts(n);
REP(i, n) REP(j, i) {
if (l[i] <= r[j] && l[j] <= r[i]) ts.add_nand(i, j);
if (l[i] <= m - l[j] - 1 && m - r[j] - 1 <= r[i]) ts.add_nand(i, ts.negate(j));
if (m - r[i] - 1 <= r[j] && l[j] <= m - l[i] - 1) ts.add_nand(ts.negate(i), j);
if (m - r[i] - 1 <= m - l[j] - 1 && m - r[j] - 1 <= m - l[i] - 1) ts.add_nand(ts.negate(i), ts.negate(j));
}
cout << (ts.build().empty() ? "NO\n" : "YES\n");
return 0;
}
emthrm