結果
問題 | No.274 The Wall |
ユーザー |
|
提出日時 | 2023-10-19 11:35:40 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 224 ms / 2,000 ms |
コード長 | 1,988 bytes |
コンパイル時間 | 1,984 ms |
コンパイル使用メモリ | 183,676 KB |
実行使用メモリ | 132,352 KB |
最終ジャッジ日時 | 2024-09-19 07:41:45 |
合計ジャッジ時間 | 3,193 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 22 |
ソースコード
#include <bits/stdc++.h>#define rep(i, p, n) for (ll i = p; i < (ll)(n); i++)#define rep2(i, p, n) for (ll i = p; i >= (ll)(n); i--)using namespace std;using ll = long long;double pi = 3.141592653589793;const long long inf = 2 * 1e9;const long long linf = 8 * 1e18;template <class T>inline bool chmax(T &a, T b){if (a < b){a = b;return 1;}return 0;}// atcoder#include <atcoder/modint>#include <atcoder/dsu>using namespace atcoder;using mint1 = modint1000000007;using mint2 = modint998244353;int main(){ll N, M;cin >> N >> M;vector<pair<ll, ll>> P(N);rep(i, 0, N) {cin >> P.at(i).first >> P.at(i).second;}vector<vector<ll>> G(N*2);rep(i, 0, N) {rep(j, i+1, N) {if (!(P.at(i).second<P.at(j).first || P.at(j).second<P.at(i).first)) {G.at(i).push_back(j + N);G.at(j + N).push_back(i);G.at(j).push_back(i + N);G.at(i + N).push_back(j);}if (!(M - 1 - P.at(i).first < P.at(j).first || P.at(j).second < M - 1 - P.at(i).second)) {G.at(i+N).push_back(j + N);G.at(j + N).push_back(i+N);G.at(j).push_back(i);G.at(i).push_back(j);}}}queue<ll> Q;vector<ll> ch(2*N, -1);ll now = 0;rep(i, 0, N*2) {if (ch.at(i)==-1) {ch.at(i)=now;Q.push(i);while(Q.size()) {ll P = Q.front();Q.pop();for(int c:G.at(P)) {if (ch.at(c)==-1) {ch.at(c) = now;Q.push(c);}}}now++;}}rep(i, 0, N) {if (ch.at(i)==ch.at(i+N)) {cout << "NO" << endl;return 0;}}cout << "YES" << endl;return 0;}