結果
| 問題 |
No.274 The Wall
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-06-10 00:49:02 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 385 ms / 2,000 ms |
| コード長 | 4,038 bytes |
| コンパイル時間 | 2,063 ms |
| コンパイル使用メモリ | 207,992 KB |
| 実行使用メモリ | 131,968 KB |
| 最終ジャッジ日時 | 2025-03-17 19:12:21 |
| 合計ジャッジ時間 | 3,832 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 23 |
ソースコード
// (◕ᴗ◕✿)
#include <bits/stdc++.h>
// #include <atcoder/all>
// using namespace atcoder;
// using mint = modint1000000007;
// using mint = modint998244353;
// using vmint = vc<mint>;using vvmint = vc<vmint>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define srep(i, s, n) for (int i = s; i < n; i++)
#define drep(i, n) for (int i = n; i >= 0; i--)
#define dsrep(i, s, n) for (int i = s; i >= n; i--)
#define len(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl
using namespace std;
template<typename T> using vc = vector<T>;
template<typename T> using vv = vc<vc<T>>;
using vi = vc<int>;using vvi = vv<int>; using vvvi = vv<vi>;
using ll = long long;using vl = vc<ll>;using vvl = vv<ll>; using vvvl = vv<vl>;
using ld = long double; using vld = vc<ld>; using vvld = vc<vld>; using vvvld = vc<vvld>;
using uint = unsigned int;
using ull = unsigned long long;
using pii = pair<int, int>;
const double pi = 3.141592653589793;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
// const int mod = 1000000007;
const int mod = 998244353;
inline bool inside(long long y, long long x, long long H, long long W) {return 0 <= y and y < H and 0 <= x and x < W; }
struct phash{
inline size_t operator()(const pair<int,int> & p) const{
const auto h1 = hash<int>()(p.first);
const auto h2 = hash<int>()(p.second);
return h1 ^ (h2 << 1);
}
};
struct twosat{
public :
twosat(int n) : nn(n){
_n = 2 * nn;
group = vi(_n, -1);
order = vi();
order.clear();
g = vvi(_n);
rg = vvi(_n);
label = 0;
answer = vc<bool>(nn);
}
void add_edge(int u, int v){
g[u].push_back(v);
rg[v].push_back(u);
}
void dfs(int s){
used[s] = true;
for (auto t : g[s]){
if (!used[t]) dfs(t);
}
order.push_back(s);
}
void rdfs(int s, int color){
group[s] = color;
nused[s] = true;
for (auto t : rg[s]){
if (!nused[t]) rdfs(t, color);
}
}
void scc(){
used = vc<bool>(_n);
nused = vc<bool>(_n);
rep(i, _n){
if (!used[i]) dfs(i);
}
drep(i, len(order) - 1){
if (!nused[order[i]]){
rdfs(order[i], label);
label++;
}
}
}
void add(int i, bool f, int j, bool g){
add_edge(2 * i + (f ? 0 : 1), 2 * j + (g ? 1 : 0));
add_edge(2 * j + (g ? 0 : 1), 2 * i + (f ? 1 : 0));
}
bool judge(){
scc();
rep(i, nn){
if (group[2 * i] == group[2 * i + 1]) return false;
answer[i] = group[2 * i] < group[2 * i + 1];
}
return true;
}
vc<bool> restore(){
return answer;
}
private :
int _n, nn, label;
vi order, group;
vvi g, rg;
vc<bool> used, nused, answer;
};
int main(){
int N, M; cin >> N >> M;
vc<pair<int, int>> pincs;
rep(i, N){
int l, r; cin >> l >> r;
pincs.push_back({l, r});
}
twosat ts(N);
rep(j, N) rep(i, j){
auto [l1, r1] = pincs[i];
auto [l2, r2] = pincs[j];
if (max(l1, l2) <= min(r1, r2)){
ts.add(i, 0, j, 0);
}
if (max(l1, M - 1 - r2) <= min(r1, M - 1 - l2)){
ts.add(i, 0, j, 1);
}
if (max(M - 1 - r1, l2) <= min(M - 1 - l1, r2)){
ts.add(i, 1, j, 0);
}
if (max(M - 1 - r1, M - 1 - r2) <= min(M - 1 - l1, M - 1 - l2)){
ts.add(i, 1, j, 1);
}
}
if (ts.judge()) cout << "YES" << endl;
else cout << "NO" << endl;
}