結果

問題 No.274 The Wall
ユーザー siman
提出日時 2023-01-10 20:18:40
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,377 bytes
コンパイル時間 1,471 ms
コンパイル使用メモリ 144,760 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-12-21 12:18:51
合計ジャッジ時間 2,490 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 14 WA * 8
権限があれば一括ダウンロードができます

ソースコード

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;
    blocks.push_back(Block(l, r));
  }

  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