結果

問題 No.274 The Wall
ユーザー simansiman
提出日時 2023-01-10 20:20:45
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,508 bytes
コンパイル時間 2,901 ms
コンパイル使用メモリ 104,276 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-23 10:19:49
合計ジャッジ時間 1,956 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

struct Block {
  int l;
  int r;

  Block(int l = -1, int r = -1) {
    this->l = l;
    this->r = r;
  }

  bool operator<(const Block &n) const {
    return l < n.l;
  }
};

int main() {
  int N, M;
  cin >> N >> M;
  vector<Block> blocks;

  for (int i = 0; i < N; ++i) {
    int l, r;
    cin >> l >> r;
    int l2 = (M - 1) - r;
    int r2 = (M - 1) - l;

    if (l < l2) {
      blocks.push_back(Block(l, r));
    } else {
      blocks.push_back(Block(l2, r2));
    }
  }

  sort(blocks.begin(), blocks.end());
  bool filled[M];
  memset(filled, false, sizeof(filled));

  for (Block &block : blocks) {
    bool ok = true;

    for (int i = block.l; i <= block.r; ++i) {
      ok &= (not filled[i]);
    }

    if (ok) {
      for (int i = block.l; i <= block.r; ++i) {
        filled[i] = true;
      }
    } else {
      int bl = block.l;
      int br = block.r;
      block = Block((M - 1) - block.r, (M - 1) - block.l);
      ok = true;

      for (int i = block.l; i <= block.r; ++i) {
        ok &= (not filled[i]);
      }

      if (ok) {
        for (int i = block.l; i <= block.r; ++i) {
          filled[i] = true;
        }
      } else {
        cout << "NO" << endl;
        return 0;
      }
    }
  }

  cout << "YES" << endl;

  return 0;
}
0