結果

問題 No.274 The Wall
ユーザー ふーらくたるふーらくたる
提出日時 2016-09-23 03:10:10
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,133 bytes
コンパイル時間 745 ms
コンパイル使用メモリ 66,520 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-28 20:33:03
合計ジャッジ時間 1,668 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 3 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 3 ms
6,944 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 3 ms
6,944 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 3 ms
6,940 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 WA -
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using P = pair<int, int>;

struct Segment {
    int lb, ub;
    bool flipped;

    bool operator>(const Segment& s) const {
        return ub == s.ub ? (lb < s.lb) : (ub > s.ub);
    }
};

int main() {
    int n, m;
    cin >> n >> m;

    priority_queue<Segment, vector<Segment>, greater<Segment>> que;
    for (int i = 0; i < n; i++) {
        int l, r;
        cin >> l >> r;
        Segment s1 = (Segment){l, r, false},
                s2 = (Segment){m - 1 - r, m - 1 - l, false};
        if (s1 > s2) {
            que.push(s2);
        } else {
            que.push(s1);
        }
    }

    int prev = -1, num = 0;
    while (!que.empty()) {
        Segment s = que.top(); que.pop();
        int l = s.lb, r = s.ub;
        if (l > prev) {
            prev = r;
            num++;
        } else if (!s.flipped) {
            Segment s2 = (Segment){m - 1 - r, m - 1 - l, true};
            que.push(s2);
        }
    }
    if (num == n) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}
0