結果
| 問題 |
No.274 The Wall
|
| ユーザー |
sugim48
|
| 提出日時 | 2015-08-28 22:35:48 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 7 ms / 2,000 ms |
| コード長 | 1,792 bytes |
| コンパイル時間 | 760 ms |
| コンパイル使用メモリ | 96,676 KB |
| 実行使用メモリ | 7,324 KB |
| 最終ジャッジ日時 | 2025-03-17 18:46:16 |
| 合計ジャッジ時間 | 1,809 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 23 |
ソースコード
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int v; ll w; };
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-8;
int INF = INT_MAX / 2;
struct union_find {
vector<int> v;
union_find(int n) : v(n, -1) {}
int find(int x) { return (v[x] < 0) ? x : (v[x] = find(v[x])); }
void unite(int x, int y) {
x = find(x); y = find(y);
if (x != y) {
if (-v[x] < -v[y]) swap(x, y);
v[x] += v[y]; v[y] = x;
}
}
bool same(int x, int y) { return find(x) == find(y); }
int size(int x) { return -v[find(x)]; }
};
bool kasanaru(int l1, int r1, int l2, int r2) {
return l2 <= r1 && l1 <= r2;
}
int main() {
int N, M; cin >> N >> M;
vector<int> L(N), R(N);
for (int i = 0; i < N; i++)
cin >> L[i] >> R[i];
union_find uf(N * 2);
for (int i = 0; i < N; i++)
for (int j = i + 1; j < N; j++) {
bool x = kasanaru(L[i], R[i], L[j], R[j]);
bool y = kasanaru(L[i], R[i], M - R[j] - 1, M - L[j] - 1);
if (x && y) {
cout << "NO" << endl;
return 0;
}
if (!x && !y) continue;
if (x) {
uf.unite(i, N + j);
uf.unite(N + i, j);
}
if (y) {
uf.unite(i, j);
uf.unite(N + i, N + j);
}
}
for (int i = 0; i < N; i++)
if (uf.same(i, N + i)) {
cout << "NO" << endl;
return 0;
}
cout << "YES" << endl;
}
sugim48