Submission #1344263

#TimeUsernameProblemLanguageResultExecution timeMemory
1344263ramzialoulouTiles (BOI24_tiles)C++20
19 / 100
29 ms6056 KiB
#include <bits/stdc++.h>
 
using namespace std;

const int N = 1009;
int a[N][N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  vector<int> X(n), Y(n);
  for (int i = 0; i < n; i++) {
    cin >> X[i] >> Y[i];
  }
  for (int i = 0; i < n; i++) {
    int j = (i - 1 + n) % n;
    if (X[i] == X[j]) {
      int l = min(Y[i], Y[j]);
      int r = max(Y[i], Y[j]);
      for (int y = l; y < r; y++) {
        a[X[i]][y] ^= 1;
      }
    }
  }
  for (int i = 1; i < N; i++) {
    for (int j = 0; j < N; j++) {
      a[i][j] ^= a[i - 1][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < m; i++) {
    bool ok = true;
    bool one = false;
    for (int j = 0; j < N - 1; j++) {
      if (a[i][j]) {
        one = true;
        if (a[i][j + 1] && a[i + 1][j] && a[i + 1][j + 1]) {
          a[i][j] = a[i + 1][j + 1] = a[i + 1][j] = a[i][j + 1] = 0;
        } else {
          ok = false;
          break;
        }
      }
    }
    if (!ok) {
      break;
    }
    if (!one) {
      ans = i + 1;
    }
  }
  cout << ans << '\n';
  return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...