結果

問題 No.274 The Wall
ユーザー h_nosonh_noson
提出日時 2016-03-25 00:04:20
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 291 ms / 2,000 ms
コード長 1,700 bytes
コンパイル時間 555 ms
コンパイル使用メモリ 68,124 KB
実行使用メモリ 99,844 KB
最終ジャッジ日時 2023-09-04 02:10:53
合計ジャッジ時間 2,471 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 127 ms
62,580 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 291 ms
99,844 KB
testcase_12 AC 14 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 5 ms
4,380 KB
testcase_15 AC 10 ms
4,376 KB
testcase_16 AC 67 ms
27,232 KB
testcase_17 AC 65 ms
26,428 KB
testcase_18 AC 67 ms
27,820 KB
testcase_19 AC 16 ms
4,380 KB
testcase_20 AC 18 ms
4,380 KB
testcase_21 AC 19 ms
4,380 KB
testcase_22 AC 19 ms
4,376 KB
testcase_23 AC 19 ms
4,384 KB
testcase_24 AC 20 ms
4,376 KB
testcase_25 AC 19 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

#define RREP(i,s,e) for (i = s; i >= e; i--)
#define rrep(i,n) RREP(i,n,0)
#define REP(i,s,e) for (i = s; i < e; i++)
#define rep(i,n) REP(i,0,n)
#define INF 100000000

typedef long long ll;

vector<int> e[4000];
vector<int> re[4000];
vector<int> vs;
bool used[4000];
int cmp[4000];
int n;

void add_edge(int u, int v) {
    e[u].push_back(v);
    re[v].push_back(u);
}

void dfs(int x) {
    int i;
    used[x] = true;
    rep (i,e[x].size()) if (!used[e[x][i]]) dfs(e[x][i]);
    vs.push_back(x);
}

void rdfs(int x, int d) {
    int i;
    used[x] = true;
    cmp[x] = d;
    rep (i,re[x].size()) if (!used[re[x][i]]) rdfs(re[x][i],d);
}

void scc() {
    int i, d;
    rep (i,2*n) if (!used[i]) dfs(i);
    fill(used,used+2*n,false);
    d = 0;
    rrep (i,2*n-1) if (!used[i]) rdfs(i,d++);
}

int main() {
    int i, j, m;
    int l[2000], r[2000];
    bool ans;
    cin >> n >> m;
    rep (i,n) cin >> l[i] >> r[i];
    rep (i,n) rep (j,i) {
        if (max(l[i],l[j])<=min(r[i],r[j])) {
            add_edge(i,j+n);
            add_edge(j,i+n);
        }
        if (max(l[i],m-1-r[j])<=min(r[i],m-1-l[j])) {
            add_edge(i,j);
            add_edge(j+n,i+n);
        }
        if (max(m-1-r[i],l[j])<=min(m-1-l[i],r[j])) {
            add_edge(i+n,j+n);
            add_edge(j,i);
        }
        if (max(m-1-r[i],m-1-l[j])<=min(m-1-l[i],m-1-l[j])) {
            add_edge(i+n,j);
            add_edge(j+n,i);
        }
    }
    scc();
    ans = true;
    rep (i,n) if (cmp[i] == cmp[i+n]) ans = false;
    if (ans)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}
0