結果
| 問題 |
No.274 The Wall
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-10-17 17:12:09 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 401 ms / 2,000 ms |
| コード長 | 2,937 bytes |
| コンパイル時間 | 4,640 ms |
| コンパイル使用メモリ | 174,240 KB |
| 実行使用メモリ | 131,840 KB |
| 最終ジャッジ日時 | 2025-03-17 19:00:10 |
| 合計ジャッジ時間 | 3,727 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 23 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
struct SCC{
int V;
vector<vector<int>> G, rG;
vector<int> vs; // 帰りがけ順の並び
vector<int> cmp; //属する強連結成分トポロジカル順序
vector<bool> used;
SCC(){}
SCC(int n){
V = n;
G = vector<vector<int>>(n);
rG = vector<vector<int>>(n);
}
void add_edge(int from, int to){
G[from].push_back(to);
rG[to].push_back(from);
}
void dfs(int v){
used[v] = true;
rep(i,G[v].size())if(!used[G[v][i]]) dfs(G[v][i]);
vs.push_back(v);
}
void rdfs(int v, int k){
used[v]=true;
cmp[v]=k;
rep(i,rG[v].size())if(!used[rG[v][i]]) rdfs(rG[v][i],k);
}
int scc(){
used = vector<bool>(V,false);
vs.clear();
rep(i,V)if(!used[i]) dfs(i);
used = vector<bool>(V,false);
cmp = vector<int>(V);
int num_scc = 0;
for(int i=vs.size()-1; i>=0; --i)if(!used[vs[i]]) rdfs(vs[i],num_scc++);
return num_scc;
}
};
struct TwoSat{
int v;
SCC graph;
// v literals
// 0~v-1: true
// v~2v-1: false
TwoSat(int num_literal){
v = num_literal;
graph = SCC(2*v);
}
inline int num(int id, bool b){return id+(b?0:v);}
void add_clause(int x, bool X, int y, bool Y){
graph.add_edge(num(x,!X), num(y,Y));
graph.add_edge(num(y,!Y), num(x,X));
}
// 割り当てが可能か調べる
bool calc(){
graph.scc();
rep(i,v)if(graph.cmp[i]==graph.cmp[v+i]) return false;
return true;
}
// リテラルの真偽値を返す
vector<bool> get_literals(){
assert(calc());
vector<bool> res(v);
rep(i,v) res[i] = (graph.cmp[i]>graph.cmp[v+i]);
return res;
}
};
using pi = pair<int,int>;
inline pi REV(pi x, int m)
{
return {m-1-x.se, m-1-x.fi};
}
inline bool COV(pi x, pi y)
{
int l = max(x.fi,y.fi);
int r = min(x.se,y.se);
return l<=r;
}
int main()
{
int n,m;
cin >>n >>m;
vector<pi> range(n);
rep(i,n) cin >>range[i].fi >>range[i].se;
TwoSat solver(n);
rep(j,n)rep(i,j)
{
rep(ii,2)rep(jj,2)
{
pi x=range[i], y=range[j];
if(!ii) x = REV(x,m);
if(!jj) y = REV(y,m);
if(COV(x,y)) solver.add_clause(i, !ii, j, !jj);
}
}
cout << (solver.calc()?"YES":"NO") << endl;
return 0;
}