結果

問題 No.274 The Wall
ユーザー 小指が強い人小指が強い人
提出日時 2016-06-25 00:28:06
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,399 bytes
コンパイル時間 748 ms
コンパイル使用メモリ 77,068 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-04 02:11:55
合計ジャッジ時間 1,825 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 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,384 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 3 ms
4,376 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 3 ms
4,380 KB
testcase_22 AC 3 ms
4,380 KB
testcase_23 AC 3 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

bool sw=true;
struct Info{
    int id,x1,x2;
    friend bool operator<(Info& a,Info& b){
        if(sw)
            return (a.x1==b.x1)?(a.x2<b.x2):(a.x1<b.x1);
        else
            return (a.x2==b.x2)?(a.x1<b.x1):(a.x2<b.x2);
    }
};

int main(){
    int i;
    int n,m;
    cin>>n>>m;
    vector<Info> v;
    for(i=0;i<n;i++){
        Info io1,io2;
        io1.id=io2.id=i;
        int x1,x2;
        cin>>x1>>x2;
        io1.x1=x1;io1.x2=x2;
        io2.x1=m-x1-1;io2.x2=m-x2-1;
        if(io2.x1>io2.x2)swap(io2.x1,io2.x2);
        v.push_back(io1);
        v.push_back(io2);
    }
    sort(v.begin(),v.end());
    bool t[2000]={0};
    int bef=-1;
    for(i=0;i<(int)v.size();i++){
        if(!t[v[i].id]&&v[i].x1>bef){
            bef=v[i].x2;
            t[v[i].id]=true;
        }
    }
    for(i=0;i<n;i++){
        if(!t[i])
            break;
    }
    if(i==n){
        cout<<"YES"<<endl;
        return 0;
    }
    sw=false;
    sort(v.begin(),v.end());
    for(i=0;i<n;i++)t[i]=false;
    bef=m;
    for(i=v.size()-1;i>=0;i--){
        if(!t[v[i].id]&&v[i].x2<bef){
            bef=v[i].x1;
            t[v[i].id]=true;
        }
    }
    for(i=0;i<n;i++){
        if(!t[i])
            break;
    }
    if(i==n){
        cout<<"YES"<<endl;
    }
    else
        cout<<"NO"<<endl;
    return 0;
}
0