結果

問題 No.274 The Wall
ユーザー MMRZ
提出日時 2024-06-09 18:39:34
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 4,915 bytes
コンパイル時間 4,515 ms
コンパイル使用メモリ 268,240 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-30 16:04:48
合計ジャッジ時間 5,526 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

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

#line 1 "274.test.cpp"
#define PROBLEM "https://yukicoder.me/problems/no/274"
#line 1 "/home/mmrz/competitive_programming/cp_templates/template/template.hpp"
# include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const double pi = acos(-1);
template<class T>constexpr T inf() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T hinf() { return inf<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); }
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); }
template<class T> bool chmin(T& a,T b) { if(a > b){a = b; return true;} return false; }
template<class T> bool chmax(T& a,T b) { if(a < b){a = b; return true;} return false; }
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(ll n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(ll n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
ll gcd(ll a, ll b) { if (b == 0)return a; return gcd(b, a%b); };
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g*b; };
ll MOD(ll x, ll m){return (x%m+m)%m; }
ll FLOOR(ll x, ll m) {ll r = (x%m+m)%m; return (x-r)/m; }
template<class T> using dijk = priority_queue<T, vector<T>, greater<T>>;
# define all(qpqpq) (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw) (wpwpw).erase(unique(all((wpwpw))),(wpwpw).end())
# define LOWER(epepe) transform(all((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr) transform(all((rprpr)),(rprpr).begin(),TU<char>)
# define rep(i,upupu) for(ll i = 0, i##_len = (upupu);(i) < (i##_len);(i)++)
# define reps(i,opopo) for(ll i = 1, i##_len = (opopo);(i) <= (i##_len);(i)++)
# define len(x) ((ll)(x).size())
# define bit(n) (1LL << (n))
# define pb push_back
# define exists(c, e) ((c).find(e) != (c).end())
struct INIT{
INIT(){
std::ios::sync_with_stdio(false);
std::cin.tie(0);
cout << fixed << setprecision(20);
}
}INIT;
namespace mmrz {
void solve();
}
int main(){
mmrz::solve();
}
#line 1 "/home/mmrz/competitive_programming/cp_templates/graph/two_sat.hpp"
#line 1 "/home/mmrz/competitive_programming/cp_templates/graph/strongly_connected_components.hpp"
struct scc_graph {
vector<vector<int>> g;
vector<vector<int>> rg;
vector<bool> used;
vector<int> cmp;
vector<int> vs;
int n;
int k;
scc_graph(int _n) : n(_n), k(0) {
g.resize(n);
rg.resize(n);
used.resize(n);
cmp.resize(n);
}
void add_edge(int a, int b) {
g[a].push_back(b);
rg[b].push_back(a);
}
void dfs(int v){
used[v] = true;
for(auto to : g[v]){
if(not used[to])dfs(to);
}
vs.pb(v);
}
void rdfs(int v, int col){
used[v] = true;
cmp[v] = col;
for(auto to : rg[v]){
if(not used[to])rdfs(to, col);
}
}
vector<vector<int>> scc() {
for(int i = 0;i < n;i++){
if(not used[i])dfs(i);
}
for(int i = 0;i < n;i++){
used[i] = false;
}
for(auto i = vs.rbegin();i != vs.rend();i++){
if(not used[*i])rdfs(*i, k++);
}
vector<vector<int>> ret(k);
for(int i = 0;i < n;i++){
ret[cmp[i]].push_back(i);
}
return ret;
}
};
#line 3 "/home/mmrz/competitive_programming/cp_templates/graph/two_sat.hpp"
struct two_sat {
int n;
scc_graph g;
two_sat(int _n) : n(_n), g(scc_graph(2*n)) {}
// (i = f1) || (j = f2)
void add_clause(int i, bool f1, int j, bool f2){
g.add_edge((i << 1) ^ !f1, (j << 1) ^ f2);
g.add_edge((j << 1) ^ !f2, (i << 1) ^ f1);
}
// (i = f1) -> (j = f2) <=> (1 = !f1) || (j = f2)
void add_if(int i, bool f1, int j, bool f2){
add_clause(i, !f1, j, f2);
}
// i
void set_true(int i){
add_clause(i, true, i, true);
}
// !i
void set_false(int i){
add_clause(i, false, i, false);
}
vector<bool> solve(){
vector<vector<int>> scc = g.scc();
vector<int> c(2*n);
for(int i = 0;i < (int)scc.size();i++){
for(auto v : scc[i]){
c[v] = i;
}
}
vector<bool> res(n);
for(int i = 0;i < n;i++){
if(c[i << 1] == c[i << 1 | 1])return vector<bool>();
res[i] = (c[i << 1] < c[i << 1 | 1]);
}
return res;
}
};
#line 5 "274.test.cpp"
void mmrz::solve(){
int n, m;
cin >> n >> m;
two_sat ts(n);
vector<int> l(n), r(n);
rep(i, n){
cin >> l[i] >> r[i];
r[i]++;
}
auto is_overlap = [&](int l1, int r1, int l2, int r2) -> bool {
return not (r1 <= l2 || r2 <= l1);
};
rep(i, n){
rep(j, n){
if(i == j)continue;
bool f1 = is_overlap(l[i], r[i], l[j], r[j]);
bool f2 = is_overlap(l[i], r[i], m-r[j], m-l[j]);
if(not f1 && not f2)continue;
if(f1 && f2){
cout << "NO" << endl;
return;
}
if(f1){
ts.add_if(i, true, j, false);
ts.add_if(i, false, j, true);
}
if(f2){
ts.add_if(i, true, j, true);
ts.add_if(i, false, j, false);
}
}
}
auto ret = ts.solve();
cout << (len(ret) ? "YES" : "NO") << endl;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0