結果

問題 No.274 The Wall
ユーザー 193s
提出日時 2017-05-17 17:55:33
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 518 ms / 2,000 ms
コード長 1,974 bytes
コンパイル時間 1,135 ms
コンパイル使用メモリ 92,472 KB
実行使用メモリ 132,224 KB
最終ジャッジ日時 2024-06-22 02:17:10
合計ジャッジ時間 3,529 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

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

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;
typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
int N, M;
int L[4000], R[4000];
vector<int> vs;
class SAT2 {
public:
int N;
vector< vector<int> > G, R;
vector<int> vs, used, ord;
SAT2 (int N) : N(N) {
G.resize(2*N);
R.resize(2*N);
used.resize(2*N);
ord.resize(2*N);
}
void add_edge(int x, int y) {
G[x].pb(y);
R[y].pb(x);
}
void dfs(int x) {
if (used[x]) return;
used[x] = true;
for (int t : G[x]) dfs(t);
vs.pb(x);
}
void rdfs(int x, int k) {
if (used[x]) return;
used[x] = true;
ord[x] = k;
for (int t : R[x]) rdfs(t, k);
}
int scc() {
rep(i, 2*N) used[i] = false;
rep(i, 2*N) dfs(i);
rep(i, 2*N) used[i] = false;
int k = 0;
for (int i=vs.size()-1; i>=0; i--) {
if (!used[vs[i]]) rdfs(vs[i], k++);
}
return k;
}
bool is_sat() {
scc();
rep(i, N) {
if (ord[i] == ord[i+N]) return false;
}
return true;
}
};
signed main() {
ios::sync_with_stdio(false); cin.tie(0);
cin >> N >> M;
rep(i, N) {
cin >> L[i] >> R[i];
L[i+N] = M-1-R[i];
R[i+N] = M-1-L[i];
}
SAT2 sat(N);
for (int x=0; x<2*N; x++) {
for (int y=x+1; y<2*N; y++) {
if (x % N == y % N) continue;
if (max(L[x], L[y]) > min(R[x], R[y])) continue;
// (not x) | (not y)
// x => not y, y => not x
//cout<<(x>=N?"!":"")<<(x%N)<<"<->"<<(y>=N?"!":"")<<(y%N)<<"\n";
sat.add_edge(x, (y+N)%(2*N));
sat.add_edge(y, (x+N)%(2*N));
}
}
if (sat.is_sat()) cout << "YES\n";
else cout << "NO\n";
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0