結果

問題 No.274 The Wall
ユーザー nasadigitalnasadigital
提出日時 2015-08-29 03:33:35
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 232 ms / 2,000 ms
コード長 2,096 bytes
コンパイル時間 1,496 ms
コンパイル使用メモリ 154,136 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-04 02:03:24
合計ジャッジ時間 4,275 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 166 ms
4,380 KB
testcase_13 AC 4 ms
4,380 KB
testcase_14 AC 34 ms
4,384 KB
testcase_15 AC 89 ms
4,380 KB
testcase_16 AC 2 ms
4,384 KB
testcase_17 AC 2 ms
4,384 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 176 ms
4,384 KB
testcase_20 AC 209 ms
4,380 KB
testcase_21 AC 219 ms
4,380 KB
testcase_22 AC 221 ms
4,376 KB
testcase_23 AC 222 ms
4,384 KB
testcase_24 AC 232 ms
4,380 KB
testcase_25 AC 231 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,m;
    cin>>m>>n;
    int l[2*m],r[2*m];
    for(int ctr1=0; ctr1<m; ctr1++)
    {
        cin>>l[ctr1]>>r[ctr1];
        l[m+ctr1]=n-r[ctr1]-1;
        r[m+ctr1]=n-l[ctr1]-1;
    }
    unordered_set<int> hs;
    vector<int> rez;
    rez.push_back(0);
    hs.insert(0);
        for(int ctr2=0; ctr2<rez.size(); ctr2++)
        {
            for(int ctr3=0; ctr3<m; ctr3++)
            {
                if(!hs.count(ctr3) && !hs.count(ctr3+m))
                {
                    bool b1=(l[rez[ctr2]]<=r[ctr3] && l[ctr3] <= r[rez[ctr2]]),b2=(l[rez[ctr2]]<=r[m+ctr3] && l[m+ctr3] <= r[rez[ctr2]]);
                    if(b1==b2)
                    {
                        if(!b1)
                            continue;
                        else
                        {
                            cout<<"NO"<<endl;
                            return 0;
                        }
                    }
                    else
                    {
                        if(b2)
                        {
                            rez.push_back(ctr3);
                            hs.insert(ctr3);
                        }
                        else
                        {
                            rez.push_back(m+ctr3);
                            hs.insert(m+ctr3);
                        }
                    }
                }
            }
            if(ctr2==rez.size()-1)
            {
                for(int ctr3=0; ctr3<m; ctr3++)
                {
                    if(hs.count(ctr3) || hs.count(ctr3+m))
                        continue;
                    rez.push_back(ctr3);
                    hs.insert(ctr3);
                    break;
                }
            }
        }
    for(int ctr1=0; ctr1<rez.size(); ctr1++)
        for(int ctr2=ctr1+1; ctr2<rez.size(); ctr2++)
            if (l[rez[ctr1]]<=r[rez[ctr2]] && l[rez[ctr2]] <= r[rez[ctr1]])
            {
                cout<<"NO"<<endl;

                return 0;
            }
    cout<<"YES"<<endl;
    return 0;
}
0