結果

問題 No.274 The Wall
ユーザー ふーらくたる
提出日時 2016-09-23 03:10:10
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,133 bytes
コンパイル時間 657 ms
コンパイル使用メモリ 66,612 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-17 16:03:34
合計ジャッジ時間 1,310 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 14 WA * 8
権限があれば一括ダウンロードができます

ソースコード

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