結果
問題 | No.274 The Wall |
ユーザー | pione |
提出日時 | 2021-03-11 01:13:24 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 480 ms / 2,000 ms |
コード長 | 4,753 bytes |
コンパイル時間 | 2,474 ms |
コンパイル使用メモリ | 224,400 KB |
実行使用メモリ | 194,816 KB |
最終ジャッジ日時 | 2024-10-12 15:24:53 |
合計ジャッジ時間 | 4,732 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,820 KB |
testcase_02 | AC | 2 ms
6,816 KB |
testcase_03 | AC | 166 ms
90,496 KB |
testcase_04 | AC | 1 ms
6,816 KB |
testcase_05 | AC | 2 ms
6,816 KB |
testcase_06 | AC | 2 ms
6,820 KB |
testcase_07 | AC | 2 ms
6,816 KB |
testcase_08 | AC | 2 ms
6,820 KB |
testcase_09 | AC | 2 ms
6,816 KB |
testcase_10 | AC | 2 ms
6,816 KB |
testcase_11 | AC | 480 ms
194,816 KB |
testcase_12 | AC | 18 ms
6,820 KB |
testcase_13 | AC | 2 ms
6,820 KB |
testcase_14 | AC | 7 ms
6,820 KB |
testcase_15 | AC | 15 ms
6,820 KB |
testcase_16 | AC | 171 ms
72,448 KB |
testcase_17 | AC | 160 ms
69,120 KB |
testcase_18 | AC | 169 ms
74,496 KB |
testcase_19 | AC | 25 ms
6,816 KB |
testcase_20 | AC | 28 ms
6,820 KB |
testcase_21 | AC | 30 ms
6,820 KB |
testcase_22 | AC | 31 ms
6,820 KB |
testcase_23 | AC | 31 ms
6,816 KB |
testcase_24 | AC | 31 ms
6,816 KB |
testcase_25 | AC | 31 ms
6,820 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; // #include <atcoder/all> // using namespace atcoder; // #define int long long #define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i) #define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i) #define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--) #define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--) #define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i) #define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i) #define irreps(i, m, n) for (long long i = ((long long)(n)-1); i > (long long)(m); ++i) #define SORT(v, n) sort(v, v + n); #define REVERSE(v, n) reverse(v, v+n); #define vsort(v) sort(v.begin(), v.end()); #define all(v) v.begin(), v.end() #define mp(n, m) make_pair(n, m); #define cinline(n) getline(cin,n); #define replace_all(s, b, a) replace(s.begin(),s.end(), b, a); #define PI (acos(-1)) #define FILL(v, n, x) fill(v, v + n, x); #define sz(x) (long long)(x.size()) using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vll = vector<ll>; using vvll = vector<vll>; using pii = pair<int, int>; using pll = pair<ll, ll>; using vs = vector<string>; using vpll = vector<pair<ll, ll>>; using vtp = vector<tuple<ll,ll,ll>>; using vb = vector<bool>; using ld = long double; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template<class t> using vc=vector<t>; template<class t> using vvc=vc<vc<t>>; const ll INF = 1e9+10; const ll MOD = 1e9+7; // const ll MOD = 998244353; const ll LINF = 1e18; struct StronglyConnectedComponents { int n; vector<vector<int>> G, rG; vector<int> order, component; vector<bool> used; void dfs(int v) { used[v] = 1; for (auto nv : G[v]) { if (!used[nv]) dfs(nv); } order.push_back(v); } void rdfs(int v, int k) { component[v] = k; for (auto nv : rG[v]) { if (component[nv] < 0) rdfs(nv, k); } } StronglyConnectedComponents(vector<vector<int>> &_G) { n = _G.size(); G = _G; rG.resize(n); component.assign(n, -1); used.resize(n); for (int v = 0; v < n; v++) { for (auto nv : G[v]) rG[nv].push_back(v); } for (int v = 0; v < n; v++) if (!used[v]) dfs(v); int k = 0; reverse(order.begin(), order.end()); for (auto v : order) if (component[v] == -1) rdfs(v, k), k++; } /// 頂点(u, v)が同じ強連結成分に含まれるか bool is_same(int u, int v) { return component[u] == component[v]; } /// 強連結成分を1つのノードに潰したグラフを再構築する vector<vector<int>> rebuild() { int N = *max_element(component.begin(), component.end()) + 1; vector<vector<int>> rebuildedG(N); set<pair<int, int>> connected; for (int v = 0; v < N; v++) { for (auto nv : G[v]) { if (component[v] != component[nv] and !connected.count(pair(v, nv))) { connected.insert(pair(v, nv)); rebuildedG[component[v]].push_back(component[nv]); } } } return rebuildedG; } }; // implication graph // 1つの区間を1つのノードと捉える // 反転した区間を¬と捉える // ある2つの区間が重なる可能性があるとき、A∨Bとして辺を張る signed main() { cin.tie( 0 ); ios::sync_with_stdio( false ); int n,m; cin>>n>>m; vc<int> l(n), r(n); rep(i,n) cin>>l[i]>>r[i]; vc<vc<int>> G(2*n); rep(i,n){ irep(j,i+1,n){ int l1=l[i], r1=r[i], l2=l[j], r2=r[j]; int L1=m-r1-1, R1=m-l1-1, L2=m-r2-1, R2=m-l2-1; if(l1<=l2 and l2<=r1 or l1<=r2 and r2<=r1 or l2<=l1 and l1<=r2){ // A∨B <=> ¬A=>B∧¬B=>A G[i+n].push_back(j); G[j+n].push_back(i); } if(l1<=L2 and L2<=r1 or l1<=R2 and R2<=r1 or L2<=l1 and l1<=R2){ // A∨¬B <=> ¬A=>¬B∧B=>A G[i+n].push_back(j+n); G[j].push_back(i); } if(L1<=l2 and l2<=R1 or L1<=r2 and r2<=R1 or l2<=L1 and L1<=r2){ // ¬A∨B <=> A=>B∧¬B=>¬A G[i].push_back(j); G[j+n].push_back(i+n); } if(L1<=L2 and L2<=R1 or L1<=R2 and R2<=R1 or L2<=L1 and L1<=R2){ // ¬A∨¬B <=> A=>¬B∧B=>¬A G[i].push_back(j+n); G[j].push_back(i+n); } } } // rep(i,n){ // cout<<i<<':'; // for(auto e: G[i]) cout<<e<<' '; // cout<<endl; // } auto scc = StronglyConnectedComponents(G); rep(i,n){ if(scc.is_same(i,i+n)){ cout<<"NO"<<endl; return 0; } } cout<<"YES"<<endl; }