結果

問題 No.274 The Wall
ユーザー koyoprokoyopro
提出日時 2015-10-11 11:52:26
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 16 ms / 2,000 ms
コード長 2,007 bytes
コンパイル時間 1,342 ms
コンパイル使用メモリ 149,100 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-04 02:07:35
合計ジャッジ時間 2,368 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

#define REP(i, n) for(int i=0; i<(n); i++)

int N,M;
struct L{
    int l, r; bool rev, fix;
    L(){
        rev = false;
        fix = false;
    }
    int le() {
        return (rev ? M - 1 - r : l);
    }
    int ri() {
        return (rev ? M - 1 - l : r);
    }
};
signed main()
{
    cin >> N >> M;
    vector<L> Ls(N);
    REP(i,N) {
        cin >> Ls[i].l >> Ls[i].r;
    }
    int k = 0;
    bool ok = true;
    while(k <= M/2) {
        vector<int> hasi;
        vector<int> hasr;
        REP(i,N) {
            L l = Ls[i];
            if (l.le() <= k && k <= l.ri()) hasi.push_back(i);
            if (M-1-l.ri() <= k && k <= M-1-l.le()) hasr.push_back(i);
        }
        // 真ん中は別処理
        if (M%2==1 && k==M/2) {
            if (hasi.size() >= 2) {
                ok = false;
                break;
            }
        } else if (hasi.size() + hasr.size() >= 3) {
            ok = false;
            break;
        }
        if (hasi.size() == 2) {
            bool hasrev = false;
            for (auto&& j : hasi) {
                if (Ls[j].fix == false && Ls[j].rev == false) {
                    Ls[j].rev = true;
                    hasrev = true;
                    break;
                }
            }
            if (!hasrev) ok = false;
        } else if (hasr.size() == 2) {
            bool hasrev = false;
            for (auto&& j : hasr) {
                if (Ls[j].fix == false && Ls[j].rev == false) {
                    Ls[j].rev = true;
                    hasrev = true;
                    break;
                }
            }
            if (!hasrev) ok = false;
        }
        if (hasi.size() + hasr.size() == 2) {
            for (auto&& j : hasi) {
                Ls[j].fix = true;
            }
            for (auto&& j : hasr) {
                Ls[j].fix = true;
            }
        }
        if (!ok) break;
        k++;
    }
    cout << (ok ? "YES" : "NO") << endl;
    return 0;
}
0