結果
問題 | No.274 The Wall |
ユーザー |
|
提出日時 | 2019-11-16 12:10:32 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 865 ms / 2,000 ms |
コード長 | 3,469 bytes |
コンパイル時間 | 1,012 ms |
コンパイル使用メモリ | 85,668 KB |
実行使用メモリ | 385,848 KB |
最終ジャッジ日時 | 2025-03-17 19:04:03 |
合計ジャッジ時間 | 3,661 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 23 |
ソースコード
#include<iostream> #include<vector> #include<algorithm> using namespace std; void dfs1(vector<vector<pair<int,int>>> &graph, vector<int> &num, vector<int> &used, int node, int &con){ if(used[node]) return ; used[node] = true; for(pair<int,int> next : graph[node]){ dfs1(graph, num, used, next.first, con); } num[con++] = node; } void dfs2(vector<vector<pair<int,int>>> &graph, vector<int> &scc, vector<int> &used, int node, int same){ if(used[node]) return ; used[node] = true; for(pair<int,int> next : graph[node]){ dfs2(graph, scc, used, next.first, same); } scc[node] = same; } void Strongly_Connected_Components(vector<vector<pair<int,int>>> &graph, vector<int> &scc){ vector<int> used(graph.size()), num(graph.size()); vector<vector<pair<int,int>>> graph2(graph.size()); int con = 0; scc.resize(graph.size()); for(int i = 0; i < graph.size(); i++){ dfs1(graph, num, used, i, con); } for(int i = 0; i < graph.size(); i++){ for(int j = 0; j < graph[i].size(); j++){ graph2[graph[i][j].first].push_back(make_pair(i, graph[i][j].second)); } } used.clear(); used.resize(graph.size()); for(int i = (int)graph.size()-1, same = 0; i >= 0; i--){ if(!used[num[i]]){ dfs2(graph2, scc, used, num[i], same); same++; } } } bool two_satisfiability(int num, vector<pair<pair<bool,int>,pair<bool,int>>>& closure, vector<bool>& val){ vector<vector<pair<int,int>>> graph(num*2); vector<int> scc; val.resize(num); for(int i = 0; i < closure.size(); i++){ graph[!closure[i].first.first + closure[i].first.second*2].push_back({closure[i].second.first + closure[i].second.second*2 ,0}); graph[!closure[i].second.first + closure[i].second.second*2].push_back({closure[i].first.first + closure[i].first.second*2 ,0}); } Strongly_Connected_Components(graph, scc); for(int i = 0; i < num*2; i += 2){ if(scc[i] == scc[i+1]){ return false; } else if(scc[i] > scc[i+1]){ val[i/2] = true; } else { val[i/2] = false; } } return true; } bool check(pair<int,int> a, pair<int,int> b){ bool res; res = (a.second - a.first + 1 + b.second - b.first + 1 > max(a.second, b.second) - min(a.first, b.first) + 1); return res; } signed main(){ int N, M; vector<pair<int,int>> in; vector<bool> val; vector<pair<pair<bool,int>,pair<bool,int>>> closure; cin>>N>>M; in.resize(N); for(int i = 0; i < N; i++){ int L, R; cin>>in[i].first>>in[i].second; } for(int i = 0; i < N; i++){ for(int j = i+1; j < N; j++){ pair<int,int> ri{M-in[i].second-1, M-in[i].first-1}, rj{M-in[j].second-1, M-in[j].first-1}; if(check(in[i], in[j])) { closure.push_back({{true,i},{true,j}}); } if(check(in[i], rj)) { closure.push_back({{true,i},{false,j}}); } if(check(ri, in[j])) { closure.push_back({{false,i},{true,j}}); } if(check(ri, rj)) { closure.push_back({{false,i},{false,j}}); } } } if(two_satisfiability(N, closure, val)){ cout<<"YES"<<endl; } else { cout<<"NO"<<endl; } return 0; }