結果

問題 No.274 The Wall
ユーザー siman
提出日時 2023-01-10 20:20:45
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,508 bytes
コンパイル時間 1,487 ms
コンパイル使用メモリ 149,212 KB
実行使用メモリ 7,324 KB
最終ジャッジ日時 2025-03-17 19:11:47
合計ジャッジ時間 2,390 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 23
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:49:15: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   49 |   bool filled[M];
      |               ^
main.cpp:49:15: note: read of non-const variable 'M' is not allowed in a constant expression
main.cpp:31:10: note: declared here
   31 |   int N, M;
      |          ^
1 warning generated.

ソースコード

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