結果

問題 No.274 The Wall
ユーザー TeruMiyake
提出日時 2020-07-04 22:30:49
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 632 ms / 2,000 ms
コード長 6,919 bytes
コンパイル時間 2,185 ms
コンパイル使用メモリ 181,624 KB
実行使用メモリ 260,224 KB
最終ジャッジ日時 2024-06-22 02:37:55
合計ジャッジ時間 3,857 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
const int INF=1e9+7;
const ll LINF=9223372036854775807;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld EPS = 1e-10; //調EPS0
int ii() { int x; if (scanf("%d", &x)==1) return x; else return 0; }
long long il() { long long x; if (scanf("%lld", &x)==1) return x; else return 0; }
string is() { string x; cin >> x; return x; }
char ic() { char x; cin >> x; return x; }
void oi(int x) { printf("%d ", x); }
void ol(long long x) { printf("%lld ", x); }
void od_nosp(double x) { printf("%.15f", x); } //
void od(double x) { printf("%.15f ", x); }
// long doublefLf
//
void os(const string &s) { printf("%s ", s.c_str()); }
void oc(const char &c) { printf("%c ", c); }
#define o_map(v){cerr << #v << endl; for(const auto& xxx: v){cout << xxx.first << " " << xxx.second << "\n";}} //
void br() { putchar('\n'); }
// #define gcd __gcd //ll C++17~gcd
// int lcm(int a, int b){return a / gcd(a, b) * b;}
#define begin_end(a) a.begin(),a.end() //sort(begin_end(vec));
#define REP(i,m,n) for(ll i=(ll)(m) ; i < (ll) (n) ; i++ )
#define rep(i,n) REP(i,0,n)
#define m_p(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define p_b push_back
#define SZ(x) ((int)(x).size) //size()unsigned
// coutpair
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << " " << p.second << ")";}
// coutvector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
int len = v.size();
for (int i = 0; i < len; ++i) {
s << v[i]; if (i < len - 1) s << " "; //"\t"Tab
}
return s;
}
// coutvector
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
int len = vv.size();
for (int i = 0; i < len; ++i) {
s << vv[i] << endl;
}
return s;
}
//ortrue
template<typename T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<typename T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}
//4 rep(i, 2)
vector<int> dx_4 = {1, 0, -1, 0};
vector<int> dy_4 = {0, 1, 0, -1};
// -------- template end - //
// - library ------------- //
// 2-SAT
// https://kopricky.github.io/code/Computation_Advanced/two_sat.html
// (a∨b) ∧ (¬b∨c) ∧ … 22-SAT
// satisfy() true vector<ll> ans 2-SAT [i] 1or0
// Xi ¬Xi
// O( + )
// ¬a∨¬b ab
// : https://yukicoder.me/problems/no/274
// 使
// ll n = ;
// TwoSAT two_sat(n);
// - ※a,¬a,b,¬b,c,¬c n = 3
// for() add_closure(x, y); // (x∨y)
// - ¬x¬y +n ex) (¬x∨y) -> (x+n, y);
// if (two_sat.satisfy()) rep(i, n) cout << two_sat.ans[i] << endl;
// else cout << "impossible" << endl;
class TwoSAT {
private:
const ll V;
vector<vector<ll> > G, rG;
vector<ll> ps, cmp;
void add_edge(ll from, ll to){
G[from].push_back(to), rG[to].push_back(from);
}
void dfs(ll u){
cmp[u] = 0;
for(ll v : G[u]){
if(cmp[v] == -1) dfs(v);
}
ps.push_back(u);
}
void rdfs(ll u, ll k){
cmp[u] = k;
for(ll v : rG[u]){
if(cmp[v] == -1) rdfs(v, k);
}
}
ll scc(){
for(ll i = 0; i < 2 * V; ++i){
if(cmp[i] == -1) dfs(i);
}
fill(cmp.begin(), cmp.end(), -1);
ll k = 0;
for(ll i = 2 * V - 1; i >= 0; --i){
if(cmp[ps[i]] == -1) rdfs(ps[i], k++);
}
return k;
}
public:
vector<ll> ans;
TwoSAT(const ll literal_count)
: V(literal_count), G(2 * V), rG(2 * V), cmp(2 * V, -1), ans(V){}
void add_closure(ll x, ll y){
add_edge((x + V) % (2 * V), y), add_edge((y + V) % (2 * V), x);
}
//
// 1, 0 ans ()
bool satisfy(){
scc();
for(ll i = 0; i < V; i++){
if(cmp[i] == cmp[V + i]) return false;
ans[i] = (cmp[i] > cmp[V + i]);
}
return true;
}
};
// --------- library end - //
int main(){
ll N, M;
cin >> N >> M;
// 使
// ll n = ;
// TwoSAT two_sat(n);
// - ※a,¬a,b,¬b,c,¬c n = 3
// for() add_closure(x, y); // (x∨y)
// - ¬x¬y +n ex) (¬x∨y) -> (x+n, y);
// if (two_sat.satisfy()) rep(i, n) cout << two_sat.ans[i] << endl;
// else cout << "impossible" << endl;
vector<pll> LRs(N * 2, pll());
rep(i, N){
ll l = il();
ll r = il();
LRs[i] = m_p(l, r);
LRs[i+N] = m_p(M-1-r, M-1-l);
}
TwoSAT two_sat(N); // =
rep(i, N) rep(j, i){
// i: 0~N-1, j: 0~i-1 i: 1~N-1, j: 0~i-1
// j < i
// i j ij, ¬i¬j(¬i∨¬j) ∧ (i∨j)
// = !(iR < jL || jR < iL)
if (!(LRs[i].second < LRs[j].first || LRs[j].second < LRs[i].first)){
two_sat.add_closure(i+N, j+N);
two_sat.add_closure(i, j);
}
// i ¬j i¬j, ¬ij(¬i∨j) ∧ (i∨¬j)
if (!(LRs[i].second < LRs[j+N].first || LRs[j+N].second < LRs[i].first)){
two_sat.add_closure(i+N, j);
two_sat.add_closure(i, j+N);
}
}
if (two_sat.satisfy()) cout << "YES" << endl;
else cout << "NO" << endl;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0