Submission #947823

# Submission time Handle Problem Language Result Execution time Memory
947823 2024-03-17T05:09:09 Z NeroZein Furniture (JOI20_furniture) C++17
5 / 100
5000 ms 4948 KB
#include "bits/stdc++.h"
using namespace std;

#ifdef Nero
#include "Deb.h"
#else
#define debug(...)
#endif

const int N = 1003;

int vis[N][N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> c(n, vector<int> (m));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> c[i][j];
    }
  }
  vector<int> dx = {0, 1}, dy = {1, 0};
  function<int(int, int)> dfs = [&](int x, int y) {
    if (x == n - 1 && y == m - 1) {
      return 1; 
    }
    int& ret = vis[x][y];
    if (ret != -1) {
      return ret;
    }
    ret = 0;
    for (int z = 0; z < 2; ++z) {
      int nx = x + dx[z], ny = y + dy[z];
      if (nx < 0 || nx >= n || ny < 0 || ny >= m || c[nx][ny]) continue; 
      ret |= dfs(nx, ny); 
    }
    return ret; 
  };
  auto check = [&](int x, int y) {
    c[x][y] = 1;
    memset(vis, -1, sizeof vis);
    if (dfs(0, 0)) {
      return true; 
    }
    c[x][y] = 0;
    return false; 
  };
  int q;
  cin >> q;
  while (q--) {
    int x, y;
    cin >> x >> y;
    --x, --y;
    cout << check(x, y) << '\n';
  }
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 65 ms 4412 KB Output is correct
2 Correct 221 ms 4412 KB Output is correct
3 Correct 341 ms 4688 KB Output is correct
4 Correct 675 ms 4484 KB Output is correct
5 Correct 721 ms 4500 KB Output is correct
6 Correct 1014 ms 4520 KB Output is correct
7 Correct 743 ms 4440 KB Output is correct
8 Correct 808 ms 4692 KB Output is correct
9 Correct 1098 ms 4512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 65 ms 4412 KB Output is correct
2 Correct 221 ms 4412 KB Output is correct
3 Correct 341 ms 4688 KB Output is correct
4 Correct 675 ms 4484 KB Output is correct
5 Correct 721 ms 4500 KB Output is correct
6 Correct 1014 ms 4520 KB Output is correct
7 Correct 743 ms 4440 KB Output is correct
8 Correct 808 ms 4692 KB Output is correct
9 Correct 1098 ms 4512 KB Output is correct
10 Execution timed out 5032 ms 4948 KB Time limit exceeded
11 Halted 0 ms 0 KB -